<?php session_start(); ?>
<?php ERROR_REPORTING(0); ?>

<?php

if (!empty($_POST["luna_sel"]) AND !empty($_POST["grp_sel"]))
{
	$_SESSION["luna_sel"]=substr($_POST["luna_sel"],0,2);
	$_SESSION["grp_sel"]=substr($_POST["grp_sel"],0,2);
}

if (isset($_POST["aplic"]) and isset($_POST["unit"]))
{
	$_SESSION["aplic"]=$_POST["aplic"];
	$_SESSION["unit"]=$_POST["unit"];
}

$luna_sel = $_SESSION["luna_sel"];
$grp_sel = $_SESSION["grp_sel"];

include 'conectare.php';

//echo "$host"." "."$username"." "."$password"." "."apponlin_".$_SESSION["aplic"]."_".$_SESSION["unit"];

	$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
	$baza="apponlin_".$_SESSION["aplic"]."_".$_SESSION["unit"];
	$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);	

mysql_query("SET NAMES 'utf8'");
	
// include and create object
	include("inc/jqgrid_dist.php");
/*
	$col = array();
	$col["title"] = "Nr.crt."; // caption of column
	$col["name"] = "nrc";
*/


	$col = array();
	$col["title"] = "Id"; // caption of column
	$col["name"] = "id";
	$col["width"] = "1";
	$col["editable"] = false;  // this column is not editable
	$col["align"] = "right";
	$col["search"] = false; // this column is not searchable
	$col["hidden"] = true; // hide column by default
	$cols[] = $col;	

	$col = array();
	$col["title"] = "Codgrp"; // caption of column
	$col["name"] = "codgrp";
	$col["width"] = "1";
	$col["editable"] = false;  // this column is not editable
	$col["align"] = "center";
	$col["search"] = false; // this column is not searchable
	$col["hidden"] = true; // hide column by default
	$cols[] = $col;	

	$col = array();
	$col["title"] = "Luna"; // caption of column
	$col["name"] = "luna";
	$col["width"] = "1";
	$col["editable"] = false;  // this column is not editable
	$col["align"] = "center";
	$col["search"] = false; // this column is not searchable
	$col["hidden"] = true; // hide column by default
	$cols[] = $col;	
	
	$col = array();
	$col["title"] = "ID";
	$col["name"] = "codcopil";
	$col["width"] = "2";
	$col["editable"] = false; // this column is not editable
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$col = array();
	$col["title"] = "Nume";
	$col["name"] = "nume";
	$col["width"] = "5";
	$col["editable"] = false; // this column is editable
	$col["align"] = "left";
	$col["search"] = true; // this column is searchable
	$cols[] = $col;

	$col = array();
	$col["title"] = "Prenume";
	$col["name"] = "prenume";
	$col["width"] = "5";
	$col["editable"] = false; // this column is not editable
	$col["align"] = "left";
	$col["search"] = true; // this column is searchable
	$cols[] = $col;

	$wluna=substr($_POST["luna_sel"],0,2);
	$wanc=date('Y');
	$wz=date('N',strtotime("01-".$wluna."-".$wanc));
	$ws="LMMJVSDLMMJVSDLMMJVSDLMMJVSDLMMJVSDLMMJVSDLMMJVSDLMMJVSD";
	$wlit=substr($ws,$wz-1,1);

/*	
	$query2="SELECT * FROM copii where codgrp='10' order by codcopil";
	$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());

	while($row2 = mysql_fetch_array( $result2))	
	{ 					
		$codcopil_arr[] = $row2["codcopil"];
	}
			
	$wvar2=$codcopil_arr[0].':'.$codcopil_arr[0];
	for ($n=1;$n<count($codcopil_arr);$n++)
	{		
		$wvar2 = $wvar2.';'.$codcopil_arr[$n].':'.$codcopil_arr[$n];
	}	
*/	
	$wlit1 = $wlit;
	$col = array();
	$col["title"] = $wlit."01";
	$col["name"] = "z_01";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
//	$col["editoptions"] = array("value"=>' : ;'.$wvar1.':'.$wvar2); 
//	$col["editoptions"] = array("value"=>$wvar2); 	
	$col["editoptions"] = array("value"=>' : ;P:P');

	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz,1);
	$wlit2 = $wlit;
	$col = array();
	$col["title"] = $wlit."02";
	$col["name"] = "z_02";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P');  	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+1,1);
	$wlit3 = $wlit;
	$col = array();
	$col["title"] = $wlit."03";
	$col["name"] = "z_03";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+2,1);
	$wlit4 = $wlit;
	$col = array();
	$col["title"] = $wlit."04";
	$col["name"] = "z_04";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+3,1);
	$wlit5 = $wlit;
	$col = array();
	$col["title"] = $wlit."05";
	$col["name"] = "z_05";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+4,1);
	$wlit6 = $wlit;
	$col = array();
	$col["title"] = $wlit."06";
	$col["name"] = "z_06";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+5,1);
	$wlit7 = $wlit;
	$col = array();
	$col["title"] = $wlit."07";
	$col["name"] = "z_07";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+6,1);
	$wlit8 = $wlit;
	$col = array();
	$col["title"] = $wlit."08";
	$col["name"] = "z_08";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+7,1);
	$wlit9 = $wlit;
	$col = array();
	$col["title"] = $wlit."09";
	$col["name"] = "z_09";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+8,1);
	$wlit10 = $wlit;
	$col = array();
	$col["title"] = $wlit."10";
	$col["name"] = "z_10";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+9,1);
	$wlit11 = $wlit;
	$col = array();
	$col["title"] = $wlit."11";
	$col["name"] = "z_11";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+10,1);
	$wlit12 = $wlit;
	$col = array();
	$col["title"] = $wlit."12";
	$col["name"] = "z_12";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+11,1);
	$wlit13 = $wlit;
	$col = array();
	$col["title"] = $wlit."13";
	$col["name"] = "z_13";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+12,1);
	$wlit14 = $wlit;
	$col = array();
	$col["title"] = $wlit."14";
	$col["name"] = "z_14";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;	

	$wlit=substr($ws,$wz+13,1);
	$wlit15 = $wlit;
	$col = array();
	$col["title"] = $wlit."15";
	$col["name"] = "z_15";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+14,1);
	$wlit16 = $wlit;
	$col = array();
	$col["title"] = $wlit."16";
	$col["name"] = "z_16";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+15,1);
	$wlit17 = $wlit;
	$col = array();
	$col["title"] = $wlit."17";
	$col["name"] = "z_17";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+16,1);
	$wlit18 = $wlit;
	$col = array();
	$col["title"] = $wlit."18";
	$col["name"] = "z_18";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+17,1);
	$wlit19 = $wlit;
	$col = array();
	$col["title"] = $wlit."19";
	$col["name"] = "z_19";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+18,1);
	$wlit20 = $wlit;
	$col = array();
	$col["title"] = $wlit."20";
	$col["name"] = "z_20";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+19,1);
	$wlit21 = $wlit;
	$col = array();
	$col["title"] = $wlit."21";
	$col["name"] = "z_21";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+20,1);
	$wlit22 = $wlit;
	$col = array();
	$col["title"] = $wlit."22";
	$col["name"] = "z_22";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+21,1);
	$wlit23 = $wlit;
	$col = array();
	$col["title"] = $wlit."23";
	$col["name"] = "z_23";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+22,1);
	$wlit24 = $wlit;
	$col = array();
	$col["title"] = $wlit."24";
	$col["name"] = "z_24";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+23,1);
	$wlit25 = $wlit;
	$col = array();
	$col["title"] = $wlit."25";
	$col["name"] = "z_25";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+24,1);
	$wlit26 = $wlit;
	$col = array();
	$col["title"] = $wlit."26";
	$col["name"] = "z_26";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;	

	$wlit=substr($ws,$wz+25,1);
	$wlit27 = $wlit;
	$col = array();
	$col["title"] = $wlit."27";
	$col["name"] = "z_27";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+26,1);
	$wlit28 = $wlit;
	$col = array();
	$col["title"] = $wlit."28";
	$col["name"] = "z_28";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
	$cols[] = $col;

	$wlit=substr($ws,$wz+27,1);
	$wlit29 = $wlit;
	$col = array();
	$col["title"] = $wlit."29";
	$col["name"] = "z_29";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
$wanc=date('Y');
if (substr($_SESSION["luna_sel"],0,2)=="02" and $wanc<>"2016" and $wanc<>"2020" and $wanc<>"2024" and $wanc<>"2028" and $wanc<>"2032")
{
  	$col["hidden"] = true;
}
else
{
	$col["hidden"] = false;
}
	$cols[] = $col;

	$wlit=substr($ws,$wz+28,1);
	$wlit30 = $wlit;
	$col = array();
	$col["title"] = $wlit."30";
	$col["name"] = "z_30";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
if (substr($_SESSION["luna_sel"],0,2)=="02")
{
  	$col["hidden"] = true;
}
else
{
	$col["hidden"] = false;
}
	$cols[] = $col;

	
	$wlit=substr($ws,$wz+29,1);
	$wlit31 = $wlit;
	$col = array();
	$col["title"] = $wlit."31";
	$col["name"] = "z_31";
	$col["width"] = "1";
	$col["editable"] = true; // this column is not editable
	$col["edittype"] = "select";
	$col["editoptions"] = array("value"=>' : ;P:P'); 	
	$col["align"] = "center";
	$col["search"] = true; // this column is not searchable
if (substr($_SESSION["luna_sel"],0,2)=="02" or substr($_SESSION["luna_sel"],0,2)=="04" or substr($_SESSION["luna_sel"],0,2)=="06" or substr($_SESSION["luna_sel"],0,2)=="09" or substr($_SESSION["luna_sel"],0,2)=="11")
{
  	$col["hidden"] = true;
}
else
{
	$col["hidden"] = false;
}
	$cols[] = $col;

	$col = array();
	$col["title"] = "Total P";
	$col["name"] = "z_tot";
	$col["width"] = "1";
	$col["align"] = "center"; // this column is not editable
	$col["hidden"] = false;
	$cols[] = $col;
	
	$col = array();
	$col["title"] = "  ";
	$col["width"] = "1";
	$col["align"] = "CENTER"; // this column is not editable
	$col["hidden"] = false;
	$col["search"] = false; 
	$cols[] = $col;	
	
	$g = new jqgrid();

// set few params
// $grid["url"] = ""; // your paramterized URL -- defaults to REQUEST_URI
	$grid["rowNum"] = 30;
	$grid["sortname"] = 'nume,prenume,codcopil'; // by default sort grid by this field
	$grid["sortorder"] = "asc"; // ASC or DESC
	$grid["caption"] = "Prezenta"; // caption of grid
	$grid["autowidth"] = true; // expand grid to screen width
	$grid["height"] = "70%";
	$grid["multiselect"] = false; // allow you to multi-select through checkboxes	
//	$grid["altRows"] = true; // Set a zebra-striped grid, boolean
//	$grid["altclass"] = "myAltRowClass"; 
	
//$grid["add_options"] = array('width'=>'450',    
                            //"closeAfterEdit"=>true, // close dialog after add/edit
                          //  "top"=>"250", // absolute top position of dialog
                            //"left"=>"400" // absolute left position of dialog
                          //  );

	$grid["edit_options"] = array('width'=>'200',    
                            "closeAfterEdit"=>true, // close dialog after add/edit
                            "top"=>"140", // absolute top position of dialog
                            "left"=>"550" // absolute left position of dialog
                            );
//	$grid["delete_options"] = array('width'=>'450',    
//                            "closeAfterEdit"=>true, // close dialog after add/edit
//                            "top"=>"250", // absolute top position of dialog
//                            "left"=>"400" // absolute left position of dialog
//                            );
						
//	$grid["export"] = array("format"=>"xlsx", "filename"=>"my-file", "sheetname"=>"test"); // only in Premium Version

	$g->set_options($grid);

	$g->set_actions(array(	
						"add"=>false, // allow/disallow add
						"edit"=>true, // allow/disallow edit
						"delete"=>false, // allow/disallow delete
						"rowactions"=>false, // show/hide row wise edit/del/save option
//						"export"=>true, // show/hide export to excel option
						"autofilter" => true, // show/hide autofilter for search
						"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
					) 
				);
				
				
/******QUERY CU CONDITII PENTRU SELECT******\

		IF (!empty($_POST["variabila"]))
		{
			$_SESSION["variabila"]=$_POST["variabila"];
		}
		$variabila = $_SESSION["variabila"];
		
		$g->select_command = "select * from comenzi WHERE variabila='$variabila'";
*/


// you can provide custom SQL query to display data

	$g->select_command = "select * from prezenta WHERE luna='$luna_sel' AND codgrp='$grp_sel'";
					
// set database table for CRUD operations
	$g->table = "prezenta";
	
	$g->set_columns($cols);			
			
// render grid
	$out = $g->render("list1");

	$themes = array("redmond","smoothness","start","dot-luv","excite-bike","flick","ui-darkness","cupertino","dark-hive","ui-lightness");
	$i = rand(0,8);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
		<link rel="stylesheet" type="text/css" media="screen" href="js/themes/start/jquery-ui.custom.css"></link>		
		<link rel="stylesheet" type="text/css" media="screen" href="js/jqgrid/css/ui.jqgrid.css"></link>	
		<link rel="stylesheet" type="text/css" href="A21_stiluri1.css"> 
	
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	
	<script src="js/jquery.min.js" type="text/javascript"></script>
	<script src="js/jqgrid/js/i18n/grid.locale-ro.js" type="text/javascript"></script>
	<script src="js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>	
	<script src="js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>

<TITLE>Evidenta prescolari/alte diverse venituri</TITLE>

<script language="JavaScript" type="text/javascript">

var w1;
function target_popup1(form) {
		w1=window.open('', 'win01', '');
		form.target = 'win01';
}

var w3;
function target_popup3(form) {
		w3=window.open('', 'win03','width=650,height=350,top=300,left=300,toolbar=no, location=no,status=no,menubar=no,scrollbars=no,resizable=no');
			form.target = 'win03';
}
var w4;
function target_popup4(form) {
		w4=window.open('', 'win04','width=1160,height=300,top=300,left=50,toolbar=no, location=no,status=no,menubar=no,scrollbars=no,resizable=no');
		form.target = 'win04'; 
}

var w5;
function target_popup5(form) {
		w5=window.open('', 'win05','width=800,height=170,top=300,left=250,toolbar=no, location=no,status=no,menubar=no,scrollbars=no,resizable=no');
		form.target = 'win05';
}

var w10;
function target_popup10(form) {
		w10=window.open('', 'win10','width=1200,height=750,top=150,left=30,resizeable,scrollbars');
		form.target = 'win10';
}
var w11;
function target_popup11(form) {
		w11=window.open('', 'win11','width=800,height=770,top=100,left=400,resizeable,scrollbars');
		form.target = 'win11';
}

var w12;
function target_popup12(form) {
		w12=window.open('', 'win12','width=550,height=250,top=300,left=400,resizeable,scrollbars');
		form.target = 'win12';
}	

var w13;
function target_popup13(form) {
		w13=window.open('', 'win13','width=1265,height=700,top=100,left=0,resizeable,scrollbars');
		form.target = 'win13';
}	

var w14;
function target_popup14(form) {
		w14=window.open('', 'win14','width=500,height=250,top=300,left=400,resizeable,scrollbars');
		form.target = 'win14';
}

var w16;
function target_popup16(form) {
		w16=window.open('', 'win16','width=700,height=350,top=200,left=300,resizeable,scrollbars');
		form.target = 'win16';
}

if (!document.all) 
{
	document.captureEvents (Event.CLICK);
}
document.onclick = function() 
{
	if (w1 != null && !w1.closed) 
	{
		w1.focus();
	}
	if (w3 != null && !w3.closed) 
	{
		w3.focus();
	}	
	if (w4 != null && !w4.closed) 
	{
		w4.focus();
	}	
	if (w5 != null && !w5.closed) 
	{
		w5.focus();
	}	
	if (w10 != null && !w10.closed) 
	{
		w10.focus();
	}	
	if (w11 != null && !w11.closed) 
	{
		w11.focus();
	}	
	if (w12 != null && !w12.closed) 
	{
		w12.focus();
	}
	if (w13 != null && !w13.closed) 
	{
		w13.focus();
	}
	if (w14 != null && !w14.closed) 
	{
		w14.focus();
	}	
	if (w16 != null && !w16.closed) 
	{
		w16.focus();
	}		
}

function buttonClick(theButton){
    document.getElementById('grupa_sel').value = document.getElementById('grp_sel').value;
    return true;
	}
	
function buttonClick2(theButton){
    document.getElementById('grupa_sel2').value = document.getElementById('grp_sel').value;
    return true;
	}

function buttonClick4(theButton){
    document.getElementById('luna_sel_prez').value = document.getElementById('luna_sel').value;
    return true;
	}		
		
	
	
function confirm_stergere_c() {

var msg = confirm('SIGUR DORITI STERGEREA?');
	if(msg == false) {
    return false;
    }
	else
	{
	setTimeout('self.close()',500)	
	}
}

function verif_luna_prez()
{
	alert("Prezenta nu au putut fi actualizata! \nData selectata nu face parte din luna respectiva.");
}


function check1() {
	
	var t = document.getElementById("grp_sel");
	document.getElementById("grupa_sel1").value = t.options[t.selectedIndex].text;
	
	var v = document.getElementById("grp_sel");
	document.getElementById("dengrupa_sel1").value = v.options[v.selectedIndex].value;

}

function check2() {
	
	var t = document.getElementById("luna_sel");
	document.getElementById("luna_sel2").value = t.options[t.selectedIndex].text;
	
	var v = document.getElementById("luna_sel");
	document.getElementById("denluna_sel2").value = v.options[v.selectedIndex].value;

}	

function showTR(dropdown){

	var v = dropdown.options[dropdown.selectedIndex].value;
	var codgrp ="99";
	var index = v.indexOf(codgrp);
	
	//if ( v == '99-ALTE DIVERSE VENITURI')
	if (index != -1)
	{
      document.getElementById('hidden_tr1').style.display = "none";
	  document.getElementById('hidden_tr2').style.display = "block";
	  document.getElementById('hidden_tr3').style.display = "none";
	}
	else
	{
      document.getElementById('hidden_tr1').style.display = "block";
	  document.getElementById('hidden_tr2').style.display = "none";
	  document.getElementById('hidden_tr3').style.display = "block";
	}
	
}

</script>

</HEAD>
<BODY>
<style>
    .myAltRowClass { background-color: aqua; background-image: none; }
	</style>
	
<?php
ob_start();
include 'javascripts.php';
include 'conectare.php';

if ($_POST["actiune"]==="INAPOI" and !isset($_POST["tip_act"]) OR $_POST["actiune"]==="INAPOI" and isset($_POST["tip_act"]) AND $_POST["tip_act"]==="GRUPE" OR $_POST["actiune"]==="TRANSFER PREZENTA")
{	
			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);
		
			$wan2 = $_POST["an"]+1;
	
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<TR BGCOLOR=\"#4EAEF2\">";
			echo "<TD colspan=\"11\" class=\"style1\" height=\"25\" align=\"center\">";
			echo "<B> ".$_POST["den_aplic"]."</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<TR BGCOLOR=\"#A3D9FF\">";
			echo "<TD width=\"250\" class=\"style1\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
			echo "</TD>";
			echo "<TD width=\"170\" class=\"style1\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
			echo "</TD>";
			echo "</tr>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<tr>";
			echo "<FORM NAME=\"copii\" method=\"POST\" action=\"A21_copii.php\">";
			include "A21_param1.php";
			
			echo "<TD bgcolor=\"#CDE6F9\" colspan=\"25\" height=\"35\" align=\"right\">";
			//echo "<INPUT TYPE=\"button\" onClick=\"window.location='login.php'\" id=\"button3\" VALUE=\"IESIRE\">";  
			echo "<input type=\"button\" onclick=\"javascript:window.close()\" id=\"button3\" value=\"IESIRE\">";			
			echo "</td>";
			echo "</tr>";
			echo "</table>";
			
			echo "<table class=\"table1\" cellpadding=\"0\" cellspacing=\"0\">"; 		
			echo "<tr>";
			echo "<div style= \"margin-top:0px;\">";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "</tr>";
			
			$query="SELECT codgrp,dengrp FROM grupe order by codgrp";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			
			echo "<tr>";
			echo "<div style= \"margin-top:0px;\">";
			echo "<TD class=\"td1\" align=\"left\">GRUPA:&nbsp</TD>";
			echo "</tr>";
			echo "<tr>";
			echo "<TD colspan=\"15\" align=\"center\">";
			echo "<SELECT onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" NAME=\"grp_sel\" id=\"grp_sel\" onchange=\"showTR(this);\">";
			$i=0;
			while($row=mysql_fetch_array($result))
			{	
				if($i===0 and !isset($_POST["grp_sel"]))
				{
					echo "<OPTION SELECTED value=\"".$row["codgrp"]."-".$row["dengrp"]."\">".$row["dengrp"]."</OPTION>";
				}
				else
				{
					if(isset($_POST["grp_sel"]) and $row["codgrp"]===substr($_POST["grp_sel"],0,2))
					{
						echo "<OPTION SELECTED value=\"".$row["codgrp"]."-".$row["dengrp"]."\">".$row["dengrp"]."</OPTION>";
					}
					else
					{
						echo "<OPTION value=\"".$row["codgrp"]."-".$row["dengrp"]."\">".$row["dengrp"]."</OPTION>";
					}
				}
				$i++;
			}
			echo "</select>";
			echo "</TD>";
			echo "</tr>";
			echo "</div>";
	
			$query="SELECT id,luna,denluna FROM luni order by id";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			
			echo "<tr>";
			echo "<div style= \"margin-top:0px;\">";
			echo "<TD class=\"td1\" align=\"left\">LUNA:&nbsp</TD>";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<TD colspan=\"15\" align=\"center\">";
			$i=0;
			echo "<SELECT onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" NAME=\"luna_sel\" id=\"luna_sel\">";
			while($row=mysql_fetch_array($result))
			{		
				if($i===0 and !isset($_POST["luna_sel"]))
				{
					echo "<OPTION SELECTED value=\"".$row["luna"]."-".$row["denluna"]."\">".$row["denluna"]."</OPTION>";
				}
				else
				{
					if(isset($_POST["luna_sel"]) and $row["luna"]===substr($_POST["luna_sel"],0,2))
					{
						echo "<OPTION SELECTED value=\"".$row["luna"]."-".$row["denluna"]."\">".$row["denluna"]."</OPTION>";
					}
					else
					{
						echo "<OPTION value=\"".$row["luna"]."-".$row["denluna"]."\">".$row["denluna"]."</OPTION>";
					}
				}
				$i++;
			}
			echo "</select>";
			echo "</TD>";
			echo "</tr>";
			echo "</div>";

//			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"luna_sel\" id=\"luna_sel\" value=\"".$_POST["luna_sel"]."\">";
//			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"denluna_sel\" id=\"denluna_sel\" value=\"".$_POST["denluna_sel"]."\">";
//			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"grp_sel\" id=\"grp_sel\" value=\"".$_POST["grp_sel"]."\">";
//			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"dengrp_sel\" id=\"dengrp_sel\" value=\"".$_POST["dengrp_sel"]."\">";
			
			echo "<tr>";
			echo "<div style= \"margin-top:0px;\">";
			echo "<TD class=\"td1\">EDITARE:&nbsp</TD>";
			echo "</td>";
			echo "</tr>";
			
			IF (substr($_POST["grp_sel"],0,2) == 99)
			{			
				echo "<tr id=\"hidden_tr1\" style=\"display:none;\">";
				echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"EVIDENTA PRESCOLARI\" ></td>";   
				echo "</tr>"; 			
				echo "<tr id=\"hidden_tr2\">";
				echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"EVIDENTA ALTE DIVERSE VENITURI\"></td>";   
				echo "</tr>";
				echo "<tr id=\"hidden_tr3\" style=\"display:none;\">";
				echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"EVIDENTA PRESCOLARI - TOATE GRUPELE\" ></td>";   
				echo "</tr>"; 					
			}
			else
			{
				echo "<tr id=\"hidden_tr1\">";
				echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"EVIDENTA PRESCOLARI\" ></td>";   
				echo "</tr>"; 			
				echo "<tr id=\"hidden_tr2\" style=\"display:none;\">";
				echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"EVIDENTA ALTE DIVERSE VENITURI\"></td>";   
				echo "</tr>";
				echo "<tr id=\"hidden_tr3\">";
				echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"EVIDENTA PRESCOLARI - TOATE GRUPELE\" ></td>";   
				echo "</tr>"; 					
			}
			echo "</div>";
	
			IF ($_POST['prez'] == 1)
			{
				echo "<tr>";
				echo "<td height=\"25px\"><input type=\"submit\" id=\"button1_3\" name=\"actiune\" value=\"PREZENTA PRESCOLARI\"></td>";
				echo "</tr>";				
			}
  				
			echo "<tr>";
			echo "<div style= \"margin-top:0px;\">";
			echo "<TD class=\"td1\"> REZULTATE:</TD>";
			echo "</tr>";

			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1_1\" name=\"actiune\" value=\"BORDEROU DEBITE SI PLATI\"></td>";   
			echo "</tr>";  
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1_2\" name=\"actiune\" value=\"BORDEROU INCASARI\"></td>";   
			echo "</tr>";  
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1_3\" name=\"actiune\" value=\"RECAPITULATIE\"></td>";   
			echo "</tr>";			
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1_3\" name=\"actiune\" value=\"REZUMAT INCASARI\"></td>";   
			echo "</tr>";
			echo "</FORM>";

			echo "<FORM name=\"form41\" ACTION=\"A21_sel_data.php\" METHOD=\"POST\" onsubmit=\"target_popup14(this)\">";
			include "A21_param1.php";
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1_3\" name=\"actiune\" value=\"REGISTRU DE CASA\" ></td>";   
			echo "</tr>";			
			echo "</FORM>";
			
			IF ($_POST['prez'] == 1)
			{
				echo "<FORM name=\"form41\" method=\"POST\" action=\"A21_prezenta_grp.php\">";
				include "A21_param1.php";	
				
				echo "<tr>";
				echo "<td height=\"25px\"><input type=\"submit\" id=\"button1_3\" name=\"actiune\" value=\"PREZENTA GRUPE\" onclick=\"return buttonClick4(this)\"></td>";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"luna_sel_prez\" id=\"luna_sel_prez\">";
				echo "</tr>";	
				echo "</FORM>";
			}			
			
			echo "<tr>";
			echo "<TD class=\"td1\"> UTILITARE:</TD>";
			echo "</tr>";
			
			echo "<tr>";
			echo "<TD colspan=\"10\" align=\"left\">";
			echo "</td>";
			echo "</tr>";

			echo "<FORM name=\"form41\" ACTION=\"A21_tarife.php\" METHOD=\"POST\" onsubmit=\"target_popup5(this)\">";
			include "A21_param1.php";
			
	//		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"grupa_sel\" id=\"grupa_sel\" value=\"".$_POST["grp_sel"]."\">";
	//		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"dengrupa_sel\" id=\"dengrupa_sel\" value=\"".$_POST["dengrp_sel"]."\">";
			
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button\" name=\"actiune\" value=\"STABILIRE TARIFE\" onclick=\"return buttonClick(this)\"></td>";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"grupa_sel\" id=\"grupa_sel\">";		
			echo "</tr>";    
			echo "</form>";
			echo "<FORM name=\"form41\" ACTION=\"A21_utilitare.php\" METHOD=\"POST\" onsubmit=\"target_popup16(this)\">";	
			include "A21_param1.php";
			
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"DEFINIRE DATE UNITATE\" ></td>";   
			echo "</tr>";  
			
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"GRUPE PRESCOLARI\" ></td>";   
			echo "</tr>"; 
			
			 // echo "<tr>";
			 // echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"STABILIRE ZILE LIBERE\" onClick=\"check1(this);\" onMouseUp=\"check2(this);\" ></td>";   
			 // echo "</tr>";  			
			echo "</form>";
			
			echo "<FORM name=\"form41\" ACTION=\"A21_utilitare.php\" METHOD=\"POST\" onsubmit=\"target_popup12(this)\">";	
			include "A21_param1.php";

			//echo "<INPUT TYPE=\"HIDDEN\" NAME=\"luna_sel\" id=\"luna_sel2\">";
			//echo "<INPUT TYPE=\"HIDDEN\" NAME=\"denluna_sel\" id=\"denluna_sel2\">";
			//echo "<INPUT TYPE=\"HIDDEN\" NAME=\"grp_sel\" id=\"grupa_sel1\">";
			//echo "<INPUT TYPE=\"HIDDEN\" NAME=\"dengrp_sel\" id=\"dengrupa_sel1\">";
			
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"SCHIMBARE PAROLA\" onClick=\"check1(this);\" onMouseUp=\"check2(this);\"></td>";  
			echo "</tr>";  
			echo "</FORM>";
			
			echo "<FORM name=\"form41\" ACTION=\"A21_instruct.php\" METHOD=\"POST\" onsubmit=\"target_popup11(this)\">";	
			include "A21_param1.php";
			echo "<tr>";
			echo "<td height=\"25px\"><input type=\"submit\" id=\"button1\" name=\"actiune\" value=\"INSTRUCTIUNI DE UTILIZARE\"></td>";  
			echo "</tr>";  
			
			echo "<tr>";
			echo "<td>&nbsp</td>";  
			echo "</tr>";
			echo "<tr>";
			echo "<td>&nbsp</td>";  			
			echo "</tr>";

		echo "</div>";
		echo "</table>";
		echo "</form>";
		
		IF ($_POST["actiune"]==="TRANSFER PREZENTA")
		{			
			IF (substr($_POST["luna_sel"],0,2) == "01")
			{
				$w_t_val = "t_val01";
				$w_z_val = "z_val01";
				$w_d_val = "d_val01";
			}			
			ELSEIF (substr($_POST["luna_sel"],0,2) == "02")
			{
				$w_t_val = "t_val02";
				$w_z_val = "z_val02";
				$w_d_val = "d_val02";
			}			
			ELSEIF (substr($_POST["luna_sel"],0,2) == "03")
			{
				 $w_t_val = "t_val03";
				 $w_z_val = "z_val03";
				 $w_d_val = "d_val03";
			}
			ELSEIF (substr($_POST["luna_sel"],0,2) == "04")
			{
				$w_t_val = "t_val04";
				$w_z_val = "z_val04";
				$w_d_val = "d_val04";
			}			
			ELSEIF (substr($_POST["luna_sel"],0,2) == "05")
			{
				$w_t_val = "t_val05";
				$w_z_val = "z_val05";
				$w_d_val = "d_val05";
			}	
			ELSEIF (substr($_POST["luna_sel"],0,2) == "06")
			{
				$w_t_val = "t_val06";
				$w_z_val = "z_val06";
				$w_d_val = "d_val06";
			}
			ELSEIF (substr($_POST["luna_sel"],0,2) == "07")
			{
				$w_t_val = "t_val07";
				$w_z_val = "z_val07";
				$w_d_val = "d_val07";
			}	
			ELSEIF (substr($_POST["luna_sel"],0,2) == "08")
			{
				$w_t_val = "t_val08";
				$w_z_val = "z_val08";
				$w_d_val = "d_val08";
			}	
			ELSEIF (substr($_POST["luna_sel"],0,2) == "09")
			{
				$w_t_val = "t_val09";
				$w_z_val = "z_val09";
				$w_d_val = "d_val09";
			}		
			ELSEIF (substr($_POST["luna_sel"],0,2) == "10")
			{
				$w_t_val = "t_val10";
				$w_z_val = "z_val10";
				$w_d_val = "d_val10";
			}		
			ELSEIF (substr($_POST["luna_sel"],0,2) == "11")
			{
				$w_t_val = "t_val11";
				$w_z_val = "z_val11";
				$w_d_val = "d_val11";
			}	
			ELSEIF (substr($_POST["luna_sel"],0,2) == "12")
			{
				$w_t_val = "t_val12";
				$w_z_val = "z_val12";
				$w_d_val = "d_val12";
			}	
			ELSE
			{
                $w_t_val = "t_val08";
				$w_z_val = "z_val08";
				$w_d_val = "d_val08";				
				
//				$w_t_val = '';
//				$w_z_val = '';
//				$w_d_val = '';
			}	

			$wanc=date('Y');			
			
			$query="SELECT ".$w_t_val." FROM grupe WHERE codgrp=\"".substr($_POST["grp_sel"],0,2)."\"";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			$row = mysql_fetch_array($result);
			
			$w_t_val_ln = $row["$w_t_val"];
			
			$query1="SELECT * FROM prezenta WHERE luna=\"".substr($_POST["luna_sel"],0,2)."\" AND codgrp=\"".substr($_POST["grp_sel"],0,2)."\" order by nume,prenume,codcopil";
			$result1=mysql_query($query1) or die("Interogare esuata: ".mysql_error());
			
			while($row1=mysql_fetch_array($result1))
			{
				$query2="SELECT * FROM prezenta WHERE luna=\"".substr($_POST["luna_sel"],0,2)."\" AND codgrp=\"".substr($_POST["grp_sel"],0,2)."\" AND codcopil=\"".$row1["codcopil"]."\"";
				$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());
				$row2 = mysql_fetch_array($result2);	

				IF (substr($_POST["luna_sel"],0,2)=="04" or substr($_POST["luna_sel"],0,2)=="06" or substr($_POST["luna_sel"],0,2)=="09" or substr($_POST["luna_sel"],0,2)=="11")
				{
					$zile_luna = $row2['z_01'].'_'.$row2['z_02'].'_'.$row2['z_03'].'_'.$row2['z_04'].'_'.$row2['z_05'].'_'.$row2['z_06'].'_'.$row2['z_07'].'_'.$row2['z_08'].'_'.$row2['z_09'].'_'.$row2['z_10'].'_'.$row2['z_11'].'_'.$row2['z_12'].'_'.$row2['z_13'].'_'.$row2['z_14'].'_'.$row2['z_15'].'_'.$row2['z_16'].'_'.$row2['z_17'].'_'.$row2['z_18'].'_'.$row2['z_19'].'_'.$row2['z_20'].'_'.$row2['z_21'].'_'.$row2['z_22'].'_'.$row2['z_23'].'_'.$row2['z_24'].'_'.$row2['z_25'].'_'.$row2['z_26'].'_'.$row2['z_27'].'_'.$row2['z_28'].'_'.$row2['z_29'].'_'.$row2['z_30'];
				
				}
				ELSEIF (substr($_POST["luna_sel"],0,2)=="02")
				{
					 IF ($wanc<>"2016" and $wanc<>"2020" and $wanc<>"2024" and $wanc<>"2028" and $wanc<>"2032")
					 {
						$zile_luna = $row2['z_01'].'_'.$row2['z_02'].'_'.$row2['z_03'].'_'.$row2['z_04'].'_'.$row2['z_05'].'_'.$row2['z_06'].'_'.$row2['z_07'].'_'.$row2['z_08'].'_'.$row2['z_09'].'_'.$row2['z_10'].'_'.$row2['z_11'].'_'.$row2['z_12'].'_'.$row2['z_13'].'_'.$row2['z_14'].'_'.$row2['z_15'].'_'.$row2['z_16'].'_'.$row2['z_17'].'_'.$row2['z_18'].'_'.$row2['z_19'].'_'.$row2['z_20'].'_'.$row2['z_21'].'_'.$row2['z_22'].'_'.$row2['z_23'].'_'.$row2['z_24'].'_'.$row2['z_25'].'_'.$row2['z_26'].'_'.$row2['z_27'].'_'.$row2['z_28'];
					 }
					 ELSE
					 {
						$zile_luna = $row2['z_01'].'_'.$row2['z_02'].'_'.$row2['z_03'].'_'.$row2['z_04'].'_'.$row2['z_05'].'_'.$row2['z_06'].'_'.$row2['z_07'].'_'.$row2['z_08'].'_'.$row2['z_09'].'_'.$row2['z_10'].'_'.$row2['z_11'].'_'.$row2['z_12'].'_'.$row2['z_13'].'_'.$row2['z_14'].'_'.$row2['z_15'].'_'.$row2['z_16'].'_'.$row2['z_17'].'_'.$row2['z_18'].'_'.$row2['z_19'].'_'.$row2['z_20'].'_'.$row2['z_21'].'_'.$row2['z_22'].'_'.$row2['z_23'].'_'.$row2['z_24'].'_'.$row2['z_25'].'_'.$row2['z_26'].'_'.$row2['z_27'].'_'.$row2['z_28'].'_'.$row2['z_29'];
					 }
				}		
				ELSE
				{			
					$zile_luna = $row2['z_01'].'_'.$row2['z_02'].'_'.$row2['z_03'].'_'.$row2['z_04'].'_'.$row2['z_05'].'_'.$row2['z_06'].'_'.$row2['z_07'].'_'.$row2['z_08'].'_'.$row2['z_09'].'_'.$row2['z_10'].'_'.$row2['z_11'].'_'.$row2['z_12'].'_'.$row2['z_13'].'_'.$row2['z_14'].'_'.$row2['z_15'].'_'.$row2['z_16'].'_'.$row2['z_17'].'_'.$row2['z_18'].'_'.$row2['z_19'].'_'.$row2['z_20'].'_'.$row2['z_21'].'_'.$row2['z_22'].'_'.$row2['z_23'].'_'.$row2['z_24'].'_'.$row2['z_25'].'_'.$row2['z_26'].'_'.$row2['z_27'].'_'.$row2['z_28'].'_'.$row2['z_29'].'_'.$row2['z_30'].'_'.$row2['z_31'];	
				}
				
				$zile_prezente = substr_count($zile_luna,'P'); // LUNA ARE 31 DE ZILE MINUS S/D
								
				$z_tot_prez = $zile_prezente;
				$w_d_val_calc = $z_tot_prez * $w_t_val_ln;

				$query3="UPDATE copii SET ".$w_z_val."=\"".$z_tot_prez."\", ".$w_d_val."=\"".$w_d_val_calc."\" WHERE codgrp=\"".substr($_POST["grp_sel"],0,2)."\" AND codcopil=\"".$row1["codcopil"]."\" ";
				$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());	

				$query4="SELECT * FROM copii WHERE codcopil=\"".$row1["codcopil"]."\"";
				$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());
				$row4=mysql_fetch_array($result4);	

				$w_d_val00=$row4["d_val00"];
				$w_d_val01=$row4["d_val01"];
				$w_d_val02=$row4["d_val02"];
				$w_d_val03=$row4["d_val03"];
				$w_d_val04=$row4["d_val04"];
				$w_d_val05=$row4["d_val05"];
				$w_d_val06=$row4["d_val06"];
				$w_d_val07=$row4["d_val07"];
				$w_d_val08=$row4["d_val08"];
				$w_d_val09=$row4["d_val09"];
				$w_d_val10=$row4["d_val10"];
				$w_d_val11=$row4["d_val11"];
				$w_d_val12=$row4["d_val12"];	

				$w_p_val01=$row4["p_val01"];
				$w_p_val02=$row4["p_val02"];
				$w_p_val03=$row4["p_val03"];
				$w_p_val04=$row4["p_val04"];
				$w_p_val05=$row4["p_val05"];
				$w_p_val06=$row4["p_val06"];
				$w_p_val07=$row4["p_val07"];
				$w_p_val08=$row4["p_val08"];
				$w_p_val09=$row4["p_val09"];
				$w_p_val10=$row4["p_val10"];
				$w_p_val11=$row4["p_val11"];
				$w_p_val12=$row4["p_val12"];	

				$w_r_val09=($w_d_val00+$w_d_val09)-$w_p_val09;
				$w_r_val10=($w_d_val00+$w_d_val09+$w_d_val10)-($w_p_val09+$w_p_val10);
				$w_r_val11=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11)-($w_p_val09+$w_p_val10+$w_p_val11);
				$w_r_val12=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12);
				$w_r_val01=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01);
				$w_r_val02=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02);
				$w_r_val03=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03);
				$w_r_val04=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04);
				$w_r_val05=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05);
				$w_r_val06=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06);
				$w_r_val07=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07);
				$w_r_val08=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08);
				
				$query5="UPDATE copii set r_val01=\"".$w_r_val01."\", r_val02=\"".$w_r_val02."\", r_val03=\"".$w_r_val03."\", ";
				$query5=$query5."r_val04=\"".$w_r_val04."\", r_val05=\"".$w_r_val05."\", r_val06=\"".$w_r_val06."\", r_val07=\"".$w_r_val07."\", ";
				$query5=$query5."r_val08=\"".$w_r_val08."\", r_val09=\"".$w_r_val09."\", r_val10=\"".$w_r_val10."\", r_val11=\"".$w_r_val11."\", ";
				$query5=$query5."r_val12=\"".$w_r_val12."\" ";
				$query5=$query5."WHERE codcopil = \"".$row1["codcopil"]."\"";
				$result5=mysql_query($query5) or die("Interogare esuata: ".mysql_error());					
			}
			
			echo '<script type="text/javascript">alert("Transferul si actualizarea debitelor s-a realizat cu succes!");</script>';
		}
		

		mysql_close($connection);
}

if ($_POST["actiune"]==="PREZENTA PRESCOLARI" OR (ISSET($_POST["tip_act"]) and $_POST["tip_act"]==="PREZENTA ZI"))
{
	$wan2 = $_POST["an"]+1;

	echo "<CENTER>";
	echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "<TR BGCOLOR=\"#4EAEF2\">";
	echo "<TD colspan=\"11\" class=\"style1\" height=\"25\" align=\"center\">";
	echo "<B> ".$_POST["den_aplic"]."</B>";
	echo "</TD>";
	echo "</TR>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "<TR BGCOLOR=\"#A3D9FF\">";
	echo "<TD width=\"250\" class=\"style1\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
	echo "</TD>";
	echo "<TD width=\"160\" class=\"style1\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
	echo "</TD>";
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "</table>";
	
	echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	echo "<tr>";
	echo "<td colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "</table>";
	
	$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
	$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
	$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
	
	echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup3(this)\">";
	include 'A21_param1.php';
	
	$wdenluna_sel=substr($_POST["luna_sel"],3,strlen($_POST["luna_sel"])-3);
	$wdengrp_sel=substr($_POST["grp_sel"],3,strlen($_POST["grp_sel"])-3);
	
	echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
	echo "<TR>";
	echo "<TD align=\"center\" class=\"td_print2\">";	
	echo "<B>PREZENTA PRESCOLARI LA &nbsp<U>".$wdengrp_sel."</B>";
	echo "<BR>";
	echo "</TD>";
	echo "</TR>";
	echo "</TABLE>";
	echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"50%\" border=0>";
	echo "<TR>";
	echo "<TD align=\"center\" class=\"td_print2\">";
	echo "<B>LUNA:&nbsp<U>".$wdenluna_sel."</U></B>";
	echo "<BR>";
	echo "</TD>";
	echo "</TR>";
	echo "</TABLE>";

	echo "</FORM>";
	
	
	echo "<FORM name=\"form41\" ACTION=\"A21_sel_data.php\" METHOD=\"POST\" onsubmit=\"target_popup14(this)\">";
	include "A21_param1.php";
	
	echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"30%\" align=\"right\" border=0>";	
	echo "<TR>";	
	echo "<TD colspan=\"1\" height=\"35\" align=\"right\">";
	echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"PREZENTA ZI\">";
	echo "</TD>";
	echo "</FORM>";

	echo "<FORM NAME=\"form\" ACTION=\"A21_lista_prez.php\" METHOD=\"POST\" target=\"_blank\">";
	include 'A21_param1.php';
	echo "<TD colspan=\"1\" height=\"35\" align=\"right\">";
	echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"LISTARE\">";
	echo "</TD>";
	echo "</FORM>";	
	
	echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
	include 'A21_param1.php';
	
	echo "<TD colspan=\"1\" height=\"35\" align=\"right\">";
	echo "<input type=\"submit\" class=\"noPrint1\" name=\"actiune\" onclick=\"return confirm('Sigur doriti transferul prezentei? \\n Debitele LA: $wdengrp_sel - LUNA: $wdenluna_sel  vor fi actualizate!');\" value=\"TRANSFER PREZENTA\">";
	echo "</TD>";	
	
	echo "<TD colspan=\"1\" height=\"35\" align=\"right\">";
	echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"INAPOI\">";
	echo "</TD>";
	echo "</TR>";
	echo "</TABLE>";
	echo "</FORM>";
	
	$wluna=substr($_POST["luna_sel"],0,2);
	$wanc=date('Y');
	$wz=date('N',strtotime("01-".$wluna."-".$wanc));
	$ws="LMMJVSDLMMJVSDLMMJVSDLMMJVSDLMMJVSDLMMJVSDLMMJVSDLMMJVSD";
	
	$wlit1=substr($ws,$wz-1,1);
	$wlit2=substr($ws,$wz,1);	
	$wlit3=substr($ws,$wz+1,1);
	$wlit4=substr($ws,$wz+2,1);	
	$wlit5=substr($ws,$wz+3,1);		
	$wlit6=substr($ws,$wz+4,1);	
	$wlit7=substr($ws,$wz+5,1);		
	$wlit8=substr($ws,$wz+6,1);		
	$wlit9=substr($ws,$wz+7,1);		
	$wlit10=substr($ws,$wz+8,1);	
	$wlit11=substr($ws,$wz+9,1);		
	$wlit12=substr($ws,$wz+10,1);	
	$wlit13=substr($ws,$wz+11,1);	
	$wlit14=substr($ws,$wz+12,1);	
	$wlit15=substr($ws,$wz+13,1);	
	$wlit16=substr($ws,$wz+14,1);	
	$wlit17=substr($ws,$wz+15,1);	
	$wlit18=substr($ws,$wz+16,1);	
	$wlit19=substr($ws,$wz+17,1);	
	$wlit20=substr($ws,$wz+18,1);	
	$wlit21=substr($ws,$wz+19,1);	
	$wlit22=substr($ws,$wz+20,1);	
	$wlit23=substr($ws,$wz+21,1);	
	$wlit24=substr($ws,$wz+22,1);	
	$wlit25=substr($ws,$wz+23,1);	
	$wlit26=substr($ws,$wz+24,1);	
	$wlit27=substr($ws,$wz+25,1);	
	$wlit28=substr($ws,$wz+26,1);	
	$wlit29=substr($ws,$wz+27,1);	
	$wlit30=substr($ws,$wz+28,1);	
	$wlit31=substr($ws,$wz+29,1);	
	
	$z_tot = '';
	
	for ($i=1;$i<=31;$i++)
	{
		//$wz[$i]='p';
		$wz[$i]='';
	}
/*				
	IF ($wlit1 == 'S' OR $wlit1 == 'D')
	{
		$wz[1]='*';
	}
	IF($wlit2 == 'S' OR $wlit2 == 'D')
	{
		$wz[2]='*';
	}	
	IF($wlit3 == 'S' OR $wlit3 == 'D')
	{
		$wz[3]='*';
	}
	IF($wlit4 == 'S' OR $wlit4 == 'D')
	{
		$wz[4]='*';
	}
	IF($wlit5 == 'S' OR $wlit5 == 'D')
	{
		$wz[5]='*';
	}
	IF($wlit6 == 'S' OR $wlit6 == 'D')
	{
		$wz[6]='*';
	}
	IF($wlit7 == 'S' OR $wlit7 == 'D')
	{
		$wz[7]='*';
	}
	IF($wlit8 == 'S' OR $wlit8 == 'D')
	{
		$wz[8]='*';
	}
	IF($wlit9 == 'S' OR $wlit9 == 'D')
	{
		$wz[9]='*';
	}	
	IF($wlit10 == 'S' OR $wlit10 == 'D')
	{
		$wz[10]='*';
	}
	IF($wlit11 == 'S' OR $wlit11 == 'D')
	{
		$wz[11]='*';
	}	
	IF($wlit12 == 'S' OR $wlit12 == 'D')
	{
		$wz[12]='*';
	}
	IF($wlit13 == 'S' OR $wlit13 == 'D')
	{
		$wz[13]='*';
	}	
	IF($wlit14 == 'S' OR $wlit14 == 'D')
	{
		$wz[14]='*';
	}		
	IF($wlit15 == 'S' OR $wlit15 == 'D')
	{
		$wz[15]='*';
	}		
	IF($wlit16 == 'S' OR $wlit16 == 'D')
	{
		$wz[16]='*';
	}	
	IF($wlit17 == 'S' OR $wlit17 == 'D')
	{
		$wz[17]='*';
	}	
	IF($wlit18 == 'S' OR $wlit18 == 'D')
	{
		$wz[18]='*';
	}
	IF($wlit19 == 'S' OR $wlit19 == 'D')
	{
		$wz[19]='*';
	}
	IF($wlit20 == 'S' OR $wlit20 == 'D')
	{
		$wz[20]='*';
	}
	IF($wlit21 == 'S' OR $wlit21 == 'D')
	{
		$wz[21]='*';
	}
	IF($wlit22 == 'S' OR $wlit22 == 'D')
	{
		$wz[22]='*';
	}
	IF($wlit23 == 'S' OR $wlit23 == 'D')
	{
		$wz[23]='*';
	}	
	IF($wlit24 == 'S' OR $wlit24 == 'D')
	{
		$wz[24]='*';
	}
	IF($wlit25 == 'S' OR $wlit25 == 'D')
	{
		$wz[25]='*';
	}		
	IF($wlit26 == 'S' OR $wlit26 == 'D')
	{
		$wz[26]='*';
	}
	IF($wlit27 == 'S' OR $wlit27 == 'D')
	{
		$wz[27]='*';
	}
	IF($wlit28 == 'S' OR $wlit28 == 'D')
	{
		$wz[28]='*';
	}		
	IF($wlit29 == 'S' OR $wlit29 == 'D')
	{
		$wz[29]='*';
	}	
	IF($wlit30 == 'S' OR $wlit30 == 'D')
	{
		$wz[30]='*';
	}	
	IF($wlit31 == 'S' OR $wlit31 == 'D')
	{
		$wz[31]='*';
	}		
*/	
	$query="SELECT codgrp,codcopil,nume,prenume FROM copii WHERE codgrp=\"".substr($_POST["grp_sel"],0,2)."\" order by nume,prenume,codcopil";
	$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
	
	$zile_prezente=0;
	$i=0;
	while($row=mysql_fetch_array($result))
	{
		$query2="SELECT luna,codgrp,codcopil FROM prezenta WHERE luna=\"".substr($_POST["luna_sel"],0,2)."\" AND codgrp=\"".substr($_POST["grp_sel"],0,2)."\" AND codcopil=\"".$row["codcopil"]."\" order by nume,prenume,codcopil";
		$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());
		$row2=mysql_fetch_array($result2);
		$total2=mysql_num_rows($result2);
		
		IF ($total2 == 0)
		{
			$query3="INSERT INTO prezenta (codgrp,codcopil,nume,prenume,luna,an,z_01,z_02,z_03,z_04,z_05,z_06,z_07,z_08,z_09,z_10,z_11,z_12,z_13,z_14,z_15,z_16,z_17,z_18,z_19,z_20,z_21,z_22,z_23,z_24,z_25,z_26,z_27,z_28,z_29,z_30,z_31,z_tot) ";
			$query3=$query3."VALUES (\"".$row["codgrp"]."\",\"".$row["codcopil"]."\",\"".$row["nume"]."\",\"".$row["prenume"]."\",\"".substr($_POST["luna_sel"],0,2)."\",\"".$wanc."\",";
			$query3=$query3."\"".$wz[1]."\",\"".$wz[2]."\",\"".$wz[3]."\",\"".$wz[4]."\",\"".$wz[5]."\",\"".$wz[6]."\",\"".$wz[7]."\",\"".$wz[8]."\",\"".$wz[9]."\",";
			$query3=$query3."\"".$wz[10]."\",\"".$wz[11]."\",\"".$wz[12]."\",\"".$wz[13]."\",\"".$wz[14]."\",\"".$wz[15]."\",\"".$wz[16]."\",\"".$wz[17]."\",\"".$wz[18]."\",";
			$query3=$query3."\"".$wz[19]."\",\"".$wz[20]."\",\"".$wz[21]."\",\"".$wz[22]."\",\"".$wz[23]."\",\"".$wz[24]."\",\"".$wz[25]."\",\"".$wz[26]."\",\"".$wz[27]."\",\"".$wz[28]."\",";
			$query3=$query3."\"".$wz[29]."\",\"".$wz[30]."\",\"".$wz[31]."\",\"".$z_tot."\")";
			$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());
		}
		
		IF($_POST["actiune"] == 'PREZENTA' OR $_POST["actiune"] == 'ABSENTA')
		{
			IF ($i==0)
			{
				$wdata_prez = $_POST['data_prez'];
				$wziua_prez = substr($wdata_prez,0,2);
				$wluna_prez = substr($wdata_prez,3,2);

				$i=1;
				
				IF($wluna_prez != substr($_POST["luna_sel"],0,2))
				{
					echo "<body onload=\"verif_luna_prez()\">";
					$i = 2;
				}
			}
			
			IF($i==1)
			{
				IF ($_POST['actiune'] == 'PREZENTA')
				{
					$val_p_a = 'P';
				}
				IF ($_POST['actiune'] == 'ABSENTA')
				{
					$val_p_a = '';
				}
					
				$query6="UPDATE prezenta SET z_$wziua_prez='$val_p_a' WHERE luna=\"".substr($_POST["luna_sel"],0,2)."\" AND codgrp=\"".substr($_POST["grp_sel"],0,2)."\" AND codcopil=\"".$row["codcopil"]."\" ";
				$result6=mysql_query($query6) or die("Interogare esuata: ".mysql_error());				
			}
		}	
								
		$query4="SELECT * FROM prezenta WHERE luna=\"".substr($_POST["luna_sel"],0,2)."\" AND codgrp=\"".substr($_POST["grp_sel"],0,2)."\" AND codcopil=\"".$row["codcopil"]."\" order by nume,prenume,codcopil";
		$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());
		$row4=mysql_fetch_array($result4);	

		IF (substr($_POST["luna_sel"],0,2)=="04" or substr($_POST["luna_sel"],0,2)=="06" or substr($_POST["luna_sel"],0,2)=="09" or substr($_POST["luna_sel"],0,2)=="11")
		{
			$zile_luna = $row4['z_01'].'_'.$row4['z_02'].'_'.$row4['z_03'].'_'.$row4['z_04'].'_'.$row4['z_05'].'_'.$row4['z_06'].'_'.$row4['z_07'].'_'.$row4['z_08'].'_'.$row4['z_09'].'_'.$row4['z_10'].'_'.$row4['z_11'].'_'.$row4['z_12'].'_'.$row4['z_13'].'_'.$row4['z_14'].'_'.$row4['z_15'].'_'.$row4['z_16'].'_'.$row4['z_17'].'_'.$row4['z_18'].'_'.$row4['z_19'].'_'.$row4['z_20'].'_'.$row4['z_21'].'_'.$row4['z_22'].'_'.$row4['z_23'].'_'.$row4['z_24'].'_'.$row4['z_25'].'_'.$row4['z_26'].'_'.$row4['z_27'].'_'.$row4['z_28'].'_'.$row4['z_29'].'_'.$row4['z_30'];
		
		}
		ELSEIF (substr($_POST["luna_sel"],0,2)=="02")
		{
			 IF ($wanc<>"2016" and $wanc<>"2020" and $wanc<>"2024" and $wanc<>"2028" and $wanc<>"2032")
			 {
				$zile_luna = $row4['z_01'].'_'.$row4['z_02'].'_'.$row4['z_03'].'_'.$row4['z_04'].'_'.$row4['z_05'].'_'.$row4['z_06'].'_'.$row4['z_07'].'_'.$row4['z_08'].'_'.$row4['z_09'].'_'.$row4['z_10'].'_'.$row4['z_11'].'_'.$row4['z_12'].'_'.$row4['z_13'].'_'.$row4['z_14'].'_'.$row4['z_15'].'_'.$row4['z_16'].'_'.$row4['z_17'].'_'.$row4['z_18'].'_'.$row4['z_19'].'_'.$row4['z_20'].'_'.$row4['z_21'].'_'.$row4['z_22'].'_'.$row4['z_23'].'_'.$row4['z_24'].'_'.$row4['z_25'].'_'.$row4['z_26'].'_'.$row4['z_27'].'_'.$row4['z_28'];
			 }
			 ELSE
			 {
				$zile_luna = $row4['z_01'].'_'.$row4['z_02'].'_'.$row4['z_03'].'_'.$row4['z_04'].'_'.$row4['z_05'].'_'.$row4['z_06'].'_'.$row4['z_07'].'_'.$row4['z_08'].'_'.$row4['z_09'].'_'.$row4['z_10'].'_'.$row4['z_11'].'_'.$row4['z_12'].'_'.$row4['z_13'].'_'.$row4['z_14'].'_'.$row4['z_15'].'_'.$row4['z_16'].'_'.$row4['z_17'].'_'.$row4['z_18'].'_'.$row4['z_19'].'_'.$row4['z_20'].'_'.$row4['z_21'].'_'.$row4['z_22'].'_'.$row4['z_23'].'_'.$row4['z_24'].'_'.$row4['z_25'].'_'.$row4['z_26'].'_'.$row4['z_27'].'_'.$row4['z_28'].'_'.$row4['z_29'];
			 }
		}		
		ELSE
		{			
			$zile_luna = $row4['z_01'].'_'.$row4['z_02'].'_'.$row4['z_03'].'_'.$row4['z_04'].'_'.$row4['z_05'].'_'.$row4['z_06'].'_'.$row4['z_07'].'_'.$row4['z_08'].'_'.$row4['z_09'].'_'.$row4['z_10'].'_'.$row4['z_11'].'_'.$row4['z_12'].'_'.$row4['z_13'].'_'.$row4['z_14'].'_'.$row4['z_15'].'_'.$row4['z_16'].'_'.$row4['z_17'].'_'.$row4['z_18'].'_'.$row4['z_19'].'_'.$row4['z_20'].'_'.$row4['z_21'].'_'.$row4['z_22'].'_'.$row4['z_23'].'_'.$row4['z_24'].'_'.$row4['z_25'].'_'.$row4['z_26'].'_'.$row4['z_27'].'_'.$row4['z_28'].'_'.$row4['z_29'].'_'.$row4['z_30'].'_'.$row4['z_31'];	
		}
		
		$zile_prezente = substr_count($zile_luna,'P'); // LUNA ARE 31 DE ZILE MINUS S/D
		
		$query5="UPDATE prezenta SET z_tot=\"".$zile_prezente."\" WHERE luna=\"".substr($_POST["luna_sel"],0,2)."\" AND codgrp=\"".substr($_POST["grp_sel"],0,2)."\" AND codcopil=\"".$row["codcopil"]."\" ";
		$result5=mysql_query($query5) or die("Interogare esuata: ".mysql_error());		

	}	
			
	echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	echo "<TR>";		
	echo $out;
	echo "</TR>";
	echo "</TABLE>";

	mysql_close($connection);	
}
	
if ($_POST["actiune"]==="EVIDENTA PRESCOLARI" OR $_POST["actiune"]=="EVIDENTA PRESCOLARI - TOATE GRUPELE"
		OR $_POST["actiune"]==="CONFIRM" AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="COPIL"
		OR $_POST["actiune"]==="MODIFIC" AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="COPIL"
		OR $_POST["actiune"]==="STERGE"  AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="COPIL"
		
		OR $_POST["actiune"]==="INAPOI"  AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="PLA"
		OR $_POST["actiune"]==="INAPOI"  AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DEB"
		or substr($_POST["actiune"],0,4)==="CAUT" AND isset($_POST["tip_act_caut"]) and $_POST["tip_act_caut"]==="CAUTC")
{
			$wan2 = $_POST["an"]+1;
			
			$toate_grp = 'NU';
			IF ($_POST["actiune"]==="EVIDENTA PRESCOLARI - TOATE GRUPELE" OR (ISSET($_POST["toate_grp"]) AND $_POST["toate_grp"] === 'DA'))
			{
				$toate_grp = 'DA';
			}
		
			echo "<CENTER>";
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<TR BGCOLOR=\"#4EAEF2\">";
			echo "<TD colspan=\"11\" class=\"style1\" height=\"25\" align=\"center\">";
			echo "<B> ".$_POST["den_aplic"]."</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<TR BGCOLOR=\"#A3D9FF\">";
			echo "<TD width=\"250\" class=\"style1\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
			echo "</TD>";
			echo "<TD width=\"160\" class=\"style1\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
			echo "</TD>";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "</table>";
			
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
			echo "<tr>";
			echo "<td colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "</table>";
			
			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
			
			echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup3(this)\">";
			include 'A21_param1.php';
			
			$wdenluna_sel=substr($_POST["luna_sel"],3,strlen($_POST["luna_sel"])-3);
			$wdengrp_sel=substr($_POST["grp_sel"],3,strlen($_POST["grp_sel"])-3);
			
			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";

		IF ($toate_grp==="DA")
		{
			echo "<B>EVIDENTA PRESCOLARI - <U>TOATE GRUPELE</U></B>";
		}	
		ELSE
		{			
			echo "<B>EVIDENTA PRESCOLARI LA &nbsp<U>".$wdengrp_sel."</B>";
		}
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";
			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"50%\" border=0>";
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>LUNA:&nbsp<U>".$wdenluna_sel."</U>&nbsp&nbsp&nbsp&nbsp ANUL SCOLAR:&nbsp<U>".$_POST["an"]." - ".$wan2."</U></B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";

			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"30%; height:100%;\" border=0 align=\"right\">";
			echo "<TR>";
			echo "<TD align=\"right\" height=\"35\">";

		IF ($toate_grp==="NU")
		{
			echo "<INPUT TYPE=\"SUBMIT\" class=\"noPrint\" NAME=\"actiune\" VALUE=\"ADAUG\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"COPIL\">";
		}	

			if(isset($_POST["sel_codcopil"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
			}
			if(isset($_POST["sel_copilul"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
			}
			echo "</TD>";
			echo "</FORM>";
			
			echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
			include 'A21_param1.php';
			echo "<TD align=\"left\" height=\"35\">";
			echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"INAPOI\">";
			
			if(isset($_POST["codparinte"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codparinte\" value=\"".$_POST["codparinte"]."\">";
			}
			if(isset($_POST["sel_codcopil"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
			}
			if(isset($_POST["sel_copilul"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
			}
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";
			
			
	IF ($_POST["actiune"]==="CONFIRM" and isset($_POST["tip_act"]) AND $_POST["tip_act"] === "COPIL")
	{
		include 'A21_param1.php';
	
			$wcodcopil = $_POST["codcopil"];
			$wnume=TRIM($_POST["nume_".$wcodcopil]);						
			$wprenume=TRIM($_POST["prenume_".$wcodcopil]);
			$wparinte1=TRIM($_POST["parinte1"]);
			$wtelefon1=TRIM($_POST["telefon1"]);
			$wparinte2=TRIM($_POST["parinte2"]);
			$wtelefon2=TRIM($_POST["telefon2"]);
			$wparinte3=TRIM($_POST["parinte3"]);
			$wtelefon3=TRIM($_POST["telefon3"]);
			$wadresa=TRIM($_POST["adresa_p"]);

			$query="SELECT * FROM copii where codgrp=\"".substr($_POST["grp_sel"],0,2)."\"";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			$row = mysql_fetch_array( $result);
			
			$query2="SELECT * FROM grupe where codgrp=\"".substr($_POST["grp_sel"],0,2)."\" and (t_val01 > 0 or t_val02 > 0 or t_val03 > 0
			 or t_val04 > 0 or t_val05 > 0 or t_val06 > 0 or t_val07 > 0 or t_val08 > 0 or t_val09 > 0 or t_val10 > 0 or t_val11 > 0 or t_val12 > 0)";
			$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());
		
		if(mysql_num_rows($result) == 0 AND mysql_num_rows($result2) == 0) 
		{			
			$query4="UPDATE grupe set t_val01='0', t_val02='0', t_val03='0', ";
			$query4=$query4."t_val04='0', t_val05='0', t_val06='0', t_val07='0', ";
			$query4=$query4."t_val08='0', t_val09='0', t_val10='0', t_val11='0', ";
			$query4=$query4."t_val12='0' WHERE codgrp=\"".substr($_POST["grp_sel"],0,2)."\"";
			$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());
		}	
			
		$query0="SELECT * FROM copii where codgrp=\"".substr($_POST["grp_sel"],0,2)."\" and codcopil=(select max(codcopil) from copii where codgrp=\"".substr($_POST["grp_sel"],0,2)."\") order by codcopil";
		$result0=mysql_query($query0) or die("Interogare esuata: ".mysql_error());	
		$row0 = mysql_fetch_array( $result0);
			
		IF ($_POST["codcopil"] <> $row0["codcopil"])
		{		
			$query3="INSERT INTO copii (codgrp,codcopil,nume,prenume,parinte1,telefon1,parinte2,telefon2,parinte3,telefon3,adresa)";
			$query3=$query3."VALUES (\"".$_POST["grp_sel"]."\",\"".$wcodcopil."\",\"".$wnume."\",\"".$wprenume."\",\"".$wparinte1."\",\"".$wtelefon1."\",\"".$wparinte2."\",\"".$wtelefon2."\",\"".$wparinte3."\",\"".$wtelefon3."\",\"".$wadresa."\")";
			$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());	
		}
		else
		{
			echo '<script type="text/javascript">';
			echo 'alert("Datele au fost actualizate. Reluati!");';
			echo '</script>';
		}
	}
	
	if ($_POST["actiune"]==="MODIFIC" and isset($_POST["tip_act"]) AND $_POST["tip_act"] === "COPIL")
	{	
		include 'A21_param1.php';
		
			$wcodcopil = $_POST["codcopil"];
			$wnume=TRIM($_POST["nume_".$wcodcopil]);						
			$wprenume=TRIM($_POST["prenume_".$wcodcopil]);
			$wparinte1=TRIM($_POST["parinte1"]);
			$wtelefon1=TRIM($_POST["telefon1"]);
			$wparinte2=TRIM($_POST["parinte2"]);
			$wtelefon2=TRIM($_POST["telefon2"]);
			$wparinte3=TRIM($_POST["parinte3"]);
			$wtelefon3=TRIM($_POST["telefon3"]);
			$wadresa=TRIM($_POST["adresa_p"]);
			
			$query4="UPDATE copii set nume=\"".$wnume."\", prenume=\"".$wprenume."\", parinte1=\"".$wparinte1."\", telefon1=\"".$wtelefon1."\", parinte2=\"".$wparinte2."\", telefon2=\"".$wtelefon2."\", parinte3=\"".$wparinte3."\", telefon3=\"".$wtelefon3."\",adresa=\"".$wadresa."\" WHERE codcopil = \"".$_POST["codcopil"]."\"";
			$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());
	}
	
	if ($_POST["actiune"]==="STERGE" and isset($_POST["tip_act"]) AND $_POST["tip_act"] === "COPIL")
	{
		include 'A21_param1.php';
		
		$wcodcopil = $_POST["codcopil"];
		
		$query0="SELECT * FROM copii WHERE codcopil=\"".$wcodcopil."\" AND (d_val00 > 0 or d_val01 > 0 or d_val02 > 0 or d_val03 > 0
		 or d_val04 > 0 or d_val05 > 0 or d_val06 > 0 or d_val07 > 0 or d_val08 > 0 or d_val09 > 0 or d_val10 > 0 or d_val11 > 0 or d_val12 > 0  
		 or p_val01 > 0 or p_val02 > 0 or p_val03 > 0 or p_val04 > 0 or p_val05 > 0 or p_val06 > 0 or p_val07 > 0 or p_val08 > 0 or p_val09 > 0 or p_val10 > 0 or p_val11 > 0 or p_val12 > 0
		 or r_val01 > 0 or r_val02 > 0 or r_val03 > 0 or r_val04 > 0 or r_val05 > 0 or r_val06 > 0 or r_val07 > 0 or r_val08 > 0 or r_val09 > 0 or r_val10 > 0 or r_val11 > 0 or r_val12 > 0)";
		$result0=mysql_query($query0) or die("Interogare esuata: ".mysql_error());	
		$row0=mysql_fetch_array($result0);
		$total0=mysql_num_rows($result0);

		IF ($total0 == 0)
		{
			$query4="DELETE FROM copii WHERE codcopil = \"".$_POST["codcopil"]."\"";
			$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());
			
			$query5="DELETE FROM chitante WHERE codcopil = \"".$_POST["codcopil"]."\"";
			$result5=mysql_query($query5) or die("Interogare esuata: ".mysql_error());				
		}		
		ELSE
		{							
			echo '<script type="text/javascript">alert("Prescolarul: '.$row0["codcopil"].' - '.$row0['nume'].' '.$row0['prenume'].' are valori pe DEBITE/PLATI!\n Stergere esuata.");</script>';
		}
	}

	
	
// *****************				
		if(isset($_POST["sel_codcopil"]))
		{
			$wsel_codcopil=$_POST["sel_codcopil"];
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
		}
		else
		{
			$wsel_codcopil="";
		}
		if(isset($_POST["sel_copilul"]))
		{
			$wsel_copilul=$_POST["sel_copilul"];
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
		}
		else
		{
			$wsel_copilul="";
		}	
			
		echo "<TABLE cellSpacing=0 cellPadding=0 width=\"90%\" border=0>";
		echo "<TR>";
			
		echo "<TD colspan=\"1\" align=\"left\">";  
		echo "<INPUT name=\"sel_codcopil\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" SIZE=\"2\" type=\"text\" VALUE=\"".$wsel_codcopil."\">";
		echo "</TD>";
		echo "<TD colspan=\"1\" align=\"left\">";  
		echo "<INPUT name=\"sel_copilul\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" type=\"text\" VALUE=\"".$wsel_copilul."\">";
		echo "</TD>";
		echo "<TD colspan=\"1\" align=\"left\" height=\"30px\">";  
		echo "<INPUT TYPE=\"SUBMIT\" name=\"actiune\" class=\"noPrint\" VALUE=\"CAUT\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act_caut\" VALUE=\"CAUTC\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$toate_grp."\">";
		echo "</TD>";
		echo "</TR>";

// *******************				

				
// ************************************
				if($_POST["actiune"]==="CAUT" or isset($_POST["sel_codcopil"]) or isset($_POST["sel_copilul"]))
				{
					$wcaut_codcopil=strtoupper(trim($_POST["sel_codcopil"]));
					$wlen_codcopil=strlen($wcaut_codcopil);
					$wcaut_copilul=strtoupper(trim($_POST["sel_copilul"]));
					$wlen_copilul=strlen($wcaut_copilul);
					
					if ($toate_grp==="NU")
					{
						$query="SELECT * FROM copii WHERE codgrp=\"".substr($_POST["grp_sel"],0,2)."\" ";
						if ($wlen_codcopil<>0)
						{
							$query=$query."  and substr(upper(codcopil),1,".$wlen_codcopil.")=\"".$wcaut_codcopil."\"";
						}
						if ($wlen_copilul<>0)
						{
							$query=$query."  and substr(upper(concat(nume,' ',prenume)),1,".$wlen_copilul.")=\"".$wcaut_copilul."\"";
						}					
					}
					else
					{
						$query="SELECT * FROM copii WHERE codgrp <> '99' ";
						if ($wlen_codcopil<>0)
						{
							$query=$query." and substr(upper(codcopil),1,".$wlen_codcopil.")=\"".$wcaut_codcopil."\"";
						}
						if ($wlen_copilul<>0)
						{
							$query=$query." and substr(upper(concat(nume,' ',prenume)),1,".$wlen_copilul.")=\"".$wcaut_copilul."\"";
						}
					}
					
					$query=$query."  order by nume,prenume,codcopil";
				}
				elseif ($toate_grp==="DA")
				{
					$query="SELECT * FROM copii WHERE codgrp <> '99' order by nume,prenume,codcopil";
				}
				else
				{
					$query="SELECT * FROM copii WHERE codgrp=\"".substr($_POST["grp_sel"],0,2)."\"  order by nume,prenume,codcopil";
				}				
				$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());	
// ************************************
		
		echo "</FORM>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";
			
			echo 	"<TH align=\"center\" width=\"4%\" class=\"td35\">ID</TH>";					
			echo	"<TH align=\"center\" width=\"14%\"  class=\"td35\">Nume Prenume prescolar</TH>";	
			echo	"<TH align=\"center\" width=\"6%\" class=\"td35\">TipReg</TH>";		
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">PREC</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">SEP</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">OCT</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">NOI</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">DEC</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IAN</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">FEB</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAR</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">APR</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAI</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUN</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUL</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">AUG</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td39\">TOTAL</TH>";
			
			echo "</TR>";
			
		$i=0;
		$debit_tot=0;
		$wlu=substr($_POST["luna_sel"],0,2);
		while($row = mysql_fetch_array( $result))	
		{ 	
			$debit_tot = $row["d_val00"] + $row["d_val01"] + $row["d_val02"] + $row["d_val03"] + $row["d_val04"] + $row["d_val05"] + $row["d_val06"] + $row["d_val07"] + $row["d_val08"] + $row["d_val09"] + $row["d_val10"] + $row["d_val11"] + $row["d_val12"];
			$platit_tot = $row["p_val01"] + $row["p_val02"] + $row["p_val03"] + $row["p_val04"] + $row["p_val05"] + $row["p_val06"] + $row["p_val07"] + $row["p_val08"] + $row["p_val09"] + $row["p_val10"] + $row["p_val11"] + $row["p_val12"];
			$rest_tot = $debit_tot - $platit_tot;
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
		
			echo "<TD width=\"2%\" height=\"30px\" align=\"center\">";
					
			echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup3(this)\">";
			include 'A21_param1.php';	

			echo "<input type=\"submit\" name=\"actiune\" class=\"noPrint9\" value='<".$row["codcopil"].">'>";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"COPIL\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$toate_grp."\">";
			
			if(isset($_POST["sel_codcopil"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
			}
			if(isset($_POST["sel_copilul"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
			}
			echo "</FORM>";
			
					echo "</TD>";
					echo"<TD width=\"10%\" align=\"left\" style=\"font-weight:bold;\">";
					echo "&nbsp".trim($row["nume"])." ".trim($row["prenume"])."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" height=\"30px\" align=\"center\">";
					
			echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup4(this)\">";
			include 'A21_param1.php';
				
			echo "<input type=\"submit\" class=\"noPrint6\" NAME=\"actiune\" value=\"D-".$row["codcopil"]."\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DEB\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$toate_grp."\">";

			if(isset($_POST["sel_codcopil"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
			}
			if(isset($_POST["sel_copilul"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
			}
			echo "</FORM>";
		
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val00"]."&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val09"]."&nbsp";
				if($wlu==="09")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val10"]."&nbsp";
				if($wlu==="10")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val11"]."&nbsp";
				if($wlu==="11")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val12"]."&nbsp";
				if($wlu==="12")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val01"]."&nbsp";
				if($wlu==="01")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val02"]."&nbsp";
				if($wlu==="02")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val03"]."&nbsp";
				if($wlu==="03")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val04"]."&nbsp";
				if($wlu==="04")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val05"]."&nbsp";
				if($wlu==="05")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val06"]."&nbsp";
				if($wlu==="06")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val07"]."&nbsp";
				if($wlu==="07")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"]+$row["d_val07"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val08"]."&nbsp";
				if($wlu==="08")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"]+$row["d_val07"]+$row["d_val08"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $debit_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
			
			IF ($toate_grp === 'DA')
			{
				$query01="SELECT codgrp,dengrp FROM grupe where codgrp=\"".$row["codgrp"]."\"";
				$result01=mysql_query($query01) or die("Interogare esuata: ".mysql_error());	
				$row01 = mysql_fetch_array( $result01);
			
				//$den_grupa_arr = explode(" ", TRIM($row01["dengrp"]));
				//$den_grupa= implode(" ", array_splice($den_grupa_arr, 0, 3));
				//$den_grupa_arr = array_filter($den_grupa_arr);
				//$den_grupa = $den_grupa_arr[0].' '.$den_grupa_arr[1].' '.$den_grupa_arr[2];
				//$den_grupa = implode(",",$den_grupa_arr);
				$den_grupa = substr($row01["dengrp"], 0, strpos($row01["dengrp"], '-'));
				
				IF (empty($den_grupa))
				{
					$den_grupa = $row01["dengrp"];
				}
			}
			ELSE	
			{
				$den_grupa = '';
			}				
		
				echo "<TD width=\"3%\" align=\"center\"> </TD>";
				echo"<TD width=\"13%\" align=\"left\">";
				echo "$den_grupa";
				echo "</TD>";
				echo"<TD width=\"1%\" height=\"30px\" align=\"center\">";
				
			echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup10(this)\">";
			include 'A21_param1.php';
				
			echo "<input type=\"submit\" class=\"noPrint6\" NAME=\"actiune\" value=\"P-".$row["codcopil"]."\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$row["nume"]."\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$row["prenume"]."\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$toate_grp."\">";

			if(isset($_POST["sel_codcopil"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
			}
			if(isset($_POST["sel_copilul"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
			}
			echo "</FORM>";
		
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo " ";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val09"]."&nbsp";
				if($wlu==="09")
				{
					$platit_ln=$row["p_val09"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val10"]."&nbsp";
				if($wlu==="10")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val11"]."&nbsp";
				if($wlu==="11")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val12"]."&nbsp";
				if($wlu==="12")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
								echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val01"]."&nbsp";
				if($wlu==="01")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val02"]."&nbsp";
				if($wlu==="02")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val03"]."&nbsp";
				if($wlu==="03")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val04"]."&nbsp";
				if($wlu==="04")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val05"]."&nbsp";
				if($wlu==="05")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val06"]."&nbsp";
				if($wlu==="06")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val07"]."&nbsp";
				if($wlu==="07")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"]+$row["p_val07"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val08"]."&nbsp";
				if($wlu==="08")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"]+$row["p_val07"]+$row["p_val08"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $platit_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";

			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
		
				echo "<TD width=\"3%\" align=\"center\"> </TD>";
				echo"<TD width=\"13%\" align=\"left\">";
				echo " ";
				echo "</TD>";
				echo"<TD width=\"1%\" height=\"30px\" align=\"center\">";
				echo "<B>REST_PL</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo " ";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="09")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val09"]."&nbsp";
				if($wlu==="09")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="10")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val10"]."&nbsp";
				if($wlu==="10")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="11")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val11"]."&nbsp";
				if($wlu==="11")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="12")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val12"]."&nbsp";
				if($wlu==="12")
				{
					echo "</B>";
				}
				echo "</TD>";
								echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="01")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val01"]."&nbsp";
				if($wlu==="01")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="02")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val02"]."&nbsp";
				if($wlu==="02")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="03")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val03"]."&nbsp";
				if($wlu==="03")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="04")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val04"]."&nbsp";
				if($wlu==="04")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="05")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val05"]."&nbsp";
				if($wlu==="05")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="06")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val06"]."&nbsp";
				if($wlu==="06")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="07")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val07"]."&nbsp";
				if($wlu==="07")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="08")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val08"]."&nbsp";
				if($wlu==="08")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $rest_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				$i++;
		}
						
		echo "</form>";
		echo "</table>";	

		mysql_close($connection);
}

if ($_POST["actiune"]=="ADAUG" and isset($_POST["tip_act"]) and $_POST["tip_act"]=="COPIL")
{
	echo "<CENTER>";
	
		echo "<FORM NAME=\"form2\" ACTION=\"A21_copii.php\" METHOD=\"POST\" TARGET=\"win01\"";
		include 'A21_param1.php';

			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		

			$query="SELECT * FROM copii where codgrp=\"".substr($_POST["grp_sel"],0,2)."\" and codcopil=(select max(codcopil) from copii where codgrp=\"".substr($_POST["grp_sel"],0,2)."\") order by codcopil";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			
			if(mysql_num_rows($result) == 0) 
			{
				$wcodcopil=substr($_POST["grp_sel"],0,2)."01";
			}
			else
			{
				$row = mysql_fetch_array($result);
				$wcodcopil = $row["codcopil"] + 1;
			}
			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>ADAUGARE PRESCOLAR</B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";
			
			echo "<TABLE cellSpacing=0 cellPadding=0 height=\"100%\" width=\"80%\" border=0>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";

			echo "<tr>";
			echo "<td colspan=\"2\">ID:</td>";
			echo "<td colspan=\"2\">";
			echo "".$wcodcopil."";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$wcodcopil."\">";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td colspan=\"2\">Nume prescolar:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"32\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"nume_".$wcodcopil."\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td colspan=\"2\">Prenume prescolar:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"32\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"prenume_".$wcodcopil."\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Parinte1:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"40\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"parinte1\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Telefon1:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"20\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"telefon1\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "</tr>";
			echo "<td colspan=\"2\">Parinte2:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"40\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"parinte2\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Telefon2:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"20\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"telefon2\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Persoana3:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"40\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"parinte3\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Telefon3:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"20\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"telefon3\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "</tr>";
			echo "<td colspan=\"2\">Adresa:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"50\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"adresa_p\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
	
			echo "</table>";
			
			include 'A21_param1.php';
			echo "<TABLE cellSpacing=0 align=\"right\" cellPadding=0 width=\"50%; height:15%;\" border=0>";
			echo "<TR>";
			echo "<TD>&nbsp</TD>";
			echo "</TR>";
			echo "<tr>";
		    echo "<td width=\"15%\" height=\"35\" align=\"right\">";
			echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"CONFIRM\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"COPIL\">";
			echo "</td>";
			echo "<td width=\"15%\" height=\"35\" align=\"left\">";
			echo "<input name=\"button\" type=\"button\" id=\"button10\" value=\"RENUNT\" onClick=\"javascript:window.close()\">";
			echo "</td>";
			echo  "</tr>";
			echo "</TABLE>";
		
			echo "</form>";
			echo "</TABLE>";
			
		mysql_close($connection);
		
}

if (substr($_POST["actiune"],0,1)=="<" AND isset($_POST["tip_act"]) and $_POST["tip_act"]=="COPIL")
{
	echo "<CENTER>";
	
		echo "<FORM NAME=\"form3\" ACTION=\"A21_copii.php\" METHOD=\"POST\" TARGET=\"win01\"";
		include 'A21_param1.php';

			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
			
			$query="SELECT * FROM copii where codcopil=\"".substr($_POST["actiune"],1,strpos($_POST["actiune"],'>')-1)."\" order by codcopil";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());		

			$row = mysql_fetch_array( $result ); 
			$wcodcopil = $row["codcopil"];

			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>EDITARE PRESCOLAR</B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";

			echo "<TABLE cellSpacing=0 cellPadding=0 height=\"100%\" width=\"80%\" border=0>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";

			echo "<tr>";
			echo "<td colspan=\"2\">ID:</td>";
			echo "<td colspan=\"2\">";
			echo "".$wcodcopil."";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$wcodcopil."\">";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td colspan=\"2\">Nume prescolar:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"32\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"nume_".$wcodcopil."\" VALUE=\"".$row["nume"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td colspan=\"2\">Prenume prescolar:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"32\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"prenume_".$wcodcopil."\" VALUE=\"".$row["prenume"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Parinte1:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"40\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"parinte1\" VALUE=\"".$row["parinte1"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Telefon1:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"20\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"telefon1\" VALUE=\"".$row["telefon1"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "</tr>";
			echo "<td colspan=\"2\">Parinte2:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"40\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"parinte2\" VALUE=\"".$row["parinte2"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Telefon2:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"20\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"telefon2\" VALUE=\"".$row["telefon2"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Persoana3:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"40\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"parinte3\" VALUE=\"".$row["parinte3"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Telefon3:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"20\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"telefon3\" VALUE=\"".$row["telefon3"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "<td colspan=\"2\">Adresa:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"50\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"adresa_p\" VALUE=\"".$row["adresa"]."\">";
			echo "</td>";
			echo "</tr>";
	
			echo "</table>";
			
			include 'A21_param1.php';
			echo "<TABLE cellSpacing=0 align=\"center\" cellPadding=0 width=\"80%; height:15%;\" border=0>";
			echo "<TR>";
			echo "<TD>&nbsp</TD>";
			echo "</TR>";
			echo "<tr>";
			echo "<td width=\"1%\" height=\"35px\" align=\"left\">";
			echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" onClick=\"return confirm_stergere_c()\" value=\"STERGE\">";	
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"COPIL\">";
			echo "</TD>";
		    echo "<td width=\"1%\" height=\"35px\" align=\"right\">";
			echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"MODIFIC\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"COPIL\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
			echo "</TD>";
		    echo "<td width=\"1%\" height=\"35px\" align=\"left\">";
			echo "<input name=\"button\" type=\"button\" id=\"button10\" value=\"RENUNT\" onClick=\"javascript:window.close()\">";
			echo "</td>";
			echo  "</tr>";
			echo "</TABLE>";
		
			echo "</form>";
			echo "</TABLE>";
			
		mysql_close($connection);
		
}

if (substr($_POST["actiune"],0,2)==="D-" AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DEB" 
	OR $_POST["actiune"]==="CONFIRM"  AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DEB")
{
	echo "<BODY id=\"bg_deb\">";
	echo "<CENTER>";  

	$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
	$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
	$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
	
			echo "<FORM NAME=\"form3\" id=\"form_confirm\" ACTION=\"A21_copii.php\" METHOD=\"POST\" TARGET=\"win01\">";
			include 'A21_param1.php';
		
			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"30%; height:100%;\" border=0 align=\"right\">";
			echo "<TR>";
			echo "<TD align=\"right\" height=\"35\">";
			echo "<INPUT TYPE=\"SUBMIT\" class=\"noPrint\" NAME=\"actiune\" onClick=\"javascript:setTimeout('window.close()',300);\" VALUE=\"INAPOI\">";
		//	echo "<INPUT TYPE=\"SUBMIT\" class=\"noPrint\" NAME=\"actiune\"  VALUE=\"INAPOI\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DEB\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
			echo "</TD>";
			echo "</TR>";
			echo "</table>";
			echo "</form>";
			
		echo "<FORM NAME=\"form3\" id=\"form_confirm\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
		include 'A21_param1.php';

		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".substr($_POST["actiune"],2,5)."\">";	
		
		$query3="SELECT * FROM grupe WHERE codgrp=\"".substr($_POST["grp_sel"],0,2)."\"";
		$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());
		$row3 = mysql_fetch_array( $result3);
		
		$w_t_val01=$row3["t_val01"];
		$w_t_val02=$row3["t_val02"];
		$w_t_val03=$row3["t_val03"];
		$w_t_val04=$row3["t_val04"];
		$w_t_val05=$row3["t_val05"];
		$w_t_val06=$row3["t_val06"];
		$w_t_val07=$row3["t_val07"];
		$w_t_val08=$row3["t_val08"];
		$w_t_val09=$row3["t_val09"];
		$w_t_val10=$row3["t_val10"];
		$w_t_val11=$row3["t_val11"];
		$w_t_val12=$row3["t_val12"];
		
		$query="SELECT * FROM copii where codcopil=\"".substr($_POST["actiune"],2,5)."\"";
		$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());		
		$row = mysql_fetch_array( $result);	
	
	IF ($_POST["actiune"]==="CONFIRM" and isset($_POST["tip_act"]) AND $_POST["tip_act"] === "DEB")
	{
		echo "<FORM NAME=\"form3\" id=\"form_confirm\" ACTION=\"A21_copii.php\" METHOD=\"POST\" >";
		include 'A21_param1.php';
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$_POST["codcopil"]."\">";
		
		$query2="SELECT * FROM copii ";
		$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());
	//	$row = mysql_fetch_array( $result);
	
		$i=0;
		while ($row2 = mysql_fetch_array( $result2))
		{			
			$query="SELECT * FROM copii WHERE codcopil=\"".$_POST["codcopil"]."\"";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			$row = mysql_fetch_array( $result);
		
			$w_z_val01=$_POST["z_val01"];
			$w_z_val02=$_POST["z_val02"];
			$w_z_val03=$_POST["z_val03"];
			$w_z_val04=$_POST["z_val04"];
			$w_z_val05=$_POST["z_val05"];
			$w_z_val06=$_POST["z_val06"];
			$w_z_val07=$_POST["z_val07"];
			$w_z_val08=$_POST["z_val08"];
			$w_z_val09=$_POST["z_val09"];
			$w_z_val10=$_POST["z_val10"];
			$w_z_val11=$_POST["z_val11"];
			$w_z_val12=$_POST["z_val12"];
		
			$w_d_val00=$_POST["d_val00"];

			IF ($w_t_val01 === "0")
			{
			$w_d_val01 = 0;
			}
			else
			{
			$w_d_val01=$w_z_val01 * $w_t_val01;
			}
			IF ($w_t_val02 === "0")
			{
			$w_d_val02 = 0;
			}
			else
			{
			$w_d_val02=$w_z_val02 * $w_t_val02;
			}
			IF ($w_t_val03 === "0")
			{
			$w_d_val03 = 0;
			}
			else
			{
			$w_d_val03=$w_z_val03 * $w_t_val03;
			}
			IF ($w_t_val04 === "0")
			{
			$w_d_val04 = 0;
			}
			else
			{
			$w_d_val04=$w_z_val04 * $w_t_val04;
			}
			IF ($w_t_val05 === "0")
			{
			$w_d_val05 = 0;
			}
			else
			{
			$w_d_val05=$w_z_val05 * $w_t_val05;
			}
			IF ($w_t_val06 === "0")
			{
			$w_d_val06 = 0;
			}
			else
			{
			$w_d_val06=$w_z_val06 * $w_t_val06;
			}
			IF ($w_t_val07 === "0")
			{
			$w_d_val07 = 0;
			}
			else
			{
			$w_d_val07=$w_z_val07 * $w_t_val07;
			}
			IF ($w_t_val08 === "0")
			{
			$w_d_val08 = 0;
			}
			else
			{
			$w_d_val08=$w_z_val08 * $w_t_val08;
			}
			IF ($w_t_val09 === "0")
			{
			$w_d_val09 = 0;
			}
			else
			{
			$w_d_val09=$w_z_val09 * $w_t_val09;
			}
			IF ($w_t_val10 === "0")
			{
			$w_d_val10 = 0;
			}
			else
			{
			$w_d_val10=$w_z_val10 * $w_t_val10;
			}
			IF ($w_t_val11 === "0")
			{
			$w_d_val11 = 0;
			}
			else
			{
			$w_d_val11=$w_z_val11 * $w_t_val11;
			}
			IF ($w_t_val12 === "0")
			{
			$w_d_val12 = 0;
			}
			else
			{
			$w_d_val12=$w_z_val12 * $w_t_val12;
			}
			
			$w_p_val01=$row["p_val01"];
			$w_p_val02=$row["p_val02"];
			$w_p_val03=$row["p_val03"];
			$w_p_val04=$row["p_val04"];
			$w_p_val05=$row["p_val05"];
			$w_p_val06=$row["p_val06"];
			$w_p_val07=$row["p_val07"];
			$w_p_val08=$row["p_val08"];
			$w_p_val09=$row["p_val09"];
			$w_p_val10=$row["p_val10"];
			$w_p_val11=$row["p_val11"];
			$w_p_val12=$row["p_val12"];
/*	
			$w_r_val01=($w_d_val00+$w_d_val01)-$w_p_val01;
			$w_r_val02=($w_d_val00+$w_d_val01+$w_d_val02)-($w_p_val01+$w_p_val02);
			$w_r_val03=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03)-($w_p_val01+$w_p_val02+$w_p_val03);
			$w_r_val04=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04);
			$w_r_val05=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05);
			$w_r_val06=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06);
			$w_r_val07=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07);
			$w_r_val08=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08);		
			$w_r_val09=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08+$w_d_val09)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08+$w_p_val09);
			$w_r_val10=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08+$w_d_val09+$w_d_val10)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08+$w_p_val09+$w_p_val10);
			$w_r_val11=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08+$w_d_val09+$w_d_val10+$w_d_val11)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08+$w_p_val09+$w_p_val10+$w_p_val11);
			$w_r_val12=($w_d_val00+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12)-($w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08+$w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12);
*/

			$w_r_val09=($w_d_val00+$w_d_val09)-$w_p_val09;
			$w_r_val10=($w_d_val00+$w_d_val09+$w_d_val10)-($w_p_val09+$w_p_val10);
			$w_r_val11=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11)-($w_p_val09+$w_p_val10+$w_p_val11);
			$w_r_val12=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12);
			$w_r_val01=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01);
			$w_r_val02=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02);
			$w_r_val03=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03);
			$w_r_val04=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04);
			$w_r_val05=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05);
			$w_r_val06=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06);
			$w_r_val07=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07);
			$w_r_val08=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08);
			
			$query4="UPDATE copii set z_val01=\"".$w_z_val01."\", z_val02=\"".$w_z_val02."\", z_val03=\"".$w_z_val03."\", ";
			$query4=$query4."z_val04=\"".$w_z_val04."\", z_val05=\"".$w_z_val05."\", z_val06=\"".$w_z_val06."\", z_val07=\"".$w_z_val07."\", ";
			$query4=$query4."z_val08=\"".$w_z_val08."\", z_val09=\"".$w_z_val09."\", z_val10=\"".$w_z_val10."\", z_val11=\"".$w_z_val11."\", ";
			$query4=$query4."z_val12=\"".$w_z_val12."\", ";
			$query4=$query4."d_val00=\"".$w_d_val00."\", d_val01=\"".$w_d_val01."\", d_val02=\"".$w_d_val02."\", d_val03=\"".$w_d_val03."\", ";
			$query4=$query4."d_val04=\"".$w_d_val04."\", d_val05=\"".$w_d_val05."\", d_val06=\"".$w_d_val06."\", d_val07=\"".$w_d_val07."\", ";
			$query4=$query4."d_val08=\"".$w_d_val08."\", d_val09=\"".$w_d_val09."\", d_val10=\"".$w_d_val10."\", d_val11=\"".$w_d_val11."\", ";
			$query4=$query4."d_val12=\"".$w_d_val12."\", ";
			$query4=$query4."r_val01=\"".$w_r_val01."\", r_val02=\"".$w_r_val02."\", r_val03=\"".$w_r_val03."\", ";
			$query4=$query4."r_val04=\"".$w_r_val04."\", r_val05=\"".$w_r_val05."\", r_val06=\"".$w_r_val06."\", r_val07=\"".$w_r_val07."\", ";
			$query4=$query4."r_val08=\"".$w_r_val08."\", r_val09=\"".$w_r_val09."\", r_val10=\"".$w_r_val10."\", r_val11=\"".$w_r_val11."\", ";
			$query4=$query4."r_val12=\"".$w_r_val12."\" ";
			$query4=$query4."WHERE codcopil = \"".$_POST["codcopil"]."\"";
			$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());	

			
			$query="SELECT * FROM copii WHERE codcopil=\"".$_POST["codcopil"]."\"";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			$row = mysql_fetch_array( $result);	
		}		
	//	echo "</form>";
	}			
		
			
			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";			
			echo "<TR>";
			echo "<TD colspan=\"32\" align=\"center\" class=\"td_print2\">";
			echo "<B>EDITARE DEBITE</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";
			
			echo 	"<TH align=\"center\" width=\"2%\" class=\"td35\">ID</TH>";					
			echo	"<TH align=\"center\" width=\"10%\"  class=\"td35\">Nume Prenume prescolar</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">&nbsp</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">PREC</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">SEP</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">OCT</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">NOI</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">DEC</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IAN</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">FEB</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAR</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">APR</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAI</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUN</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUL</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">AUG</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td39\">TOTAL</TH>";			
			echo "</TR>";	

			$debit_tot = $row["d_val00"] + $row["d_val01"] + $row["d_val02"] + $row["d_val03"] + $row["d_val04"] + $row["d_val05"] + $row["d_val06"] + $row["d_val07"] + $row["d_val08"] + $row["d_val09"] + $row["d_val10"] + $row["d_val11"] + $row["d_val12"];
			
			echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
		
				echo "<TD width=\"2%\" height=\"30px\" align=\"center\">";
				echo $row["codcopil"];
				echo "</TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "&nbsp".trim($row["nume"])." ".trim($row["prenume"])."&nbsp";
				echo "</TD>";
				echo "<TD width=\"2%\" align=\"center\">";
				echo "Nr. zile prezent";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">&nbsp</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val09\" VALUE=".$row["z_val09"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val10\" VALUE=".$row["z_val10"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val11\" VALUE=".$row["z_val11"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val12\" VALUE=".$row["z_val12"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val01\" VALUE=".$row["z_val01"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val02\" VALUE=".$row["z_val02"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val03\" VALUE=".$row["z_val03"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val04\" VALUE=".$row["z_val04"].">";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val05\" VALUE=".$row["z_val05"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val06\" VALUE=".$row["z_val06"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val07\" VALUE=".$row["z_val07"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val08\" VALUE=".$row["z_val08"].">";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp</B></TD>";
				echo "</TR>";

				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
				echo "<TD width=\"2%\" height=\"30px\" align=\"center\">";
				echo "</TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "</TD>";
				echo "<TD width=\"2%\" align=\"center\">";
				echo "Tarif / zi";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">&nbsp</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val09."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val10."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val11."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val12."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val01."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val02."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val03."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val04."&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "".$w_t_val05."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val06."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val07."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val08."&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp</TD>";
				echo "</TR>";
				echo "<TR>";
				echo "<TD colspan=\"17\">";
				echo "<hr width=\"100%\">";
				echo "</TD>";
				echo "</TR>";
				echo "<TR>";
				echo "<TD width=\"2%\" height=\"30px\" align=\"center\">";				
				echo "</TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "</TD>";
				echo "<TD width=\"2%\" align=\"center\">";
				echo "<B>TOTAL:&nbsp</B>";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" style=\"font-weight:bold;\" size=\"2\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey1(event)\" class=\"text1\" NAME=\"d_val00\" VALUE=".$row["d_val00"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val09"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val10"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val11"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val12"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val01"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val02"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val03"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val04"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>".$row["d_val05"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val06"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val07"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val08"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $debit_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				echo "</B>";
				
				echo "<TR>";
				echo "<TD>&nbsp</TD>";
				echo "</TR>";
				echo "<tr>";
			    echo "<td colspan=\"15\" width=\"15%\" height=\"35\" align=\"right\">";
			//	echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"CONFIRM\">";
				echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" value=\"CONFIRM\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DEB\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_actiune\" VALUE=\"CONF\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
				echo "</td>";
				echo "<td  colspan=\"2\" width=\"15%\" height=\"35\" align=\"left\">";
				if (!isset($_POST["tip_actiune"]))
				{	
					echo "<input name=\"button\" type=\"button\" id=\"button10_2\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"RENUNT\" >";				
				}
				else
				{
					echo "<input name=\"button\" type=\"button\" disabled=\"disabled\" id=\"button10_2\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"RENUNT\" >";	
				}			
				echo "</td>";
				echo  "</tr>";			

		echo "</form>";
		echo "</table>";	
		
		mysql_close($connection);
}

if (substr($_POST["actiune"],0,2)==="P-" and isset($_POST["tip_act"]) and $_POST["tip_act"]==="PLA")
{
	echo "<BODY id=\"bg_plati\">";
	echo "<CENTER>";

			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
			
			$query="SELECT * FROM chitante where codcopil=\"".substr($_POST["actiune"],2,5)."\" order by data_doc,id";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());		
		
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD colspan=\"6\" align=\"left\" class=\"td_print2\">";
			echo "<B>PLATI</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD colspan=\"6\" align=\"left\">";
			echo "<B>".substr($_POST["actiune"],2,5)." - ";
			echo "&nbsp".trim($_POST["nume"])." ".trim($_POST["prenume"])."&nbsp";
			echo "</B></TD>";
			echo "</TR>";
			
		echo "<FORM NAME=\"form3\" ACTION=\"A21_editare_chit.php\" METHOD=\"POST\" onsubmit=\"target_popup10(this)\">";
		include 'A21_param1.php';
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".substr($_POST["actiune"],2,5)."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";

		echo "<TR>";
		echo "<TD colspan=\"8\" height=\"35\" align=\"right\">";
		echo "<INPUT TYPE=\"button\" id=\"button11\" NAME=\"actiune\" VALUE=\"INAPOI\" onClick=\"javascript:window.close()\">";
		echo "</TD>";
		echo "</TR>";				
		echo "<TR>";
		echo "<TD colspan=\"8\" height=\"35\" align=\"right\">";
		echo "<INPUT TYPE=\"SUBMIT\" NAME=\"actiune\" id=\"button11\" VALUE=\"ADAUG\">";
		echo "</TD>";
		echo "</TR>";
		echo "<TR>";
		echo "<TD>";
		echo "&nbsp";
		echo "</TR>";
		echo "<TR>";
		echo "<TD>";
		echo "&nbsp";
		echo "</TD>";
		echo "</TR>";
		//echo "</FORM>";
		
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";			
			echo    "<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td35\">Nrc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td35\">Tip</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Nr doc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Data doc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td35\">Suma</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"35%\" class=\"td35\">Platitor</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"35%\" class=\"td35\">Reprezentand</TH>";
			echo    "<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Editare</TH>";		
			echo    "<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Listare</TH>";
			echo    "<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td39\">Anulat</TH>";			
			echo "</TR>";
			$platit_tot=0;
			$i=0;
			while ($row = mysql_fetch_array( $result))
			{
				echo "<FORM NAME=\"form3\" ACTION=\"A21_editare_chit.php\" METHOD=\"POST\" onsubmit=\"target_popup10(this)\">";
				include 'A21_param1.php';
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".substr($_POST["actiune"],2,5)."\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
				
				$data_doc = date("d-m-Y", strtotime($row["data_doc"]));
				
				if ($row["anulat"] <> 'X')
				{				
					$platit_tot = $platit_tot+$row["val_doc"];
				}
			
				if ($i-floor($i/2)*2==0)
				{
					echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
				}
				else
				{
					echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
				}
		 
				echo "<TD colspan=\"1\" width=\"5%\" height=\"25px\" align=\"center\">",$i+1,"</TD>";
				echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
				echo "&nbsp".$row["tip_doc"]."&nbsp";
				echo "</TD>";
				echo"<TD colspan=\"1\" width=\"10%\" align=\"center\">";
				if($row["tip_doc"]==="CHA")
				{
					echo "&nbsp".$row["serie_doc"]."_".$row["nr_doc"]."&nbsp";
				}
				else
				{
					echo "&nbsp".$row["nr_doc"]."&nbsp";
				}
				echo "</TD>";
				echo"<TD colspan=\"1\" width=\"10%\" align=\"center\">";
				echo "&nbsp".$data_doc."&nbsp";
				echo "</TD>";
				
				if ($row["anulat"] === 'X')
				{
					echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
					echo "0&nbsp(".$row["val_doc"].")&nbsp";
					echo "</TD>";
					echo"<TD colspan=\"1\" width=\"35%\" align=\"left\">";
					echo "&nbsp".$row["platitor"]."&nbsp";
					echo "</TD>";	
					echo"<TD colspan=\"1\" width=\"35%\" align=\"left\">";
					echo "&nbsp".$row["reprezentand"]."&nbsp";
					echo "</TD>";	
					echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "</TD>";
				}
				else
				{
					echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
					echo "&nbsp".$row["val_doc"]."&nbsp";
					echo "</TD>";
					echo"<TD colspan=\"1\" width=\"35%\" align=\"left\">";
					echo "&nbsp".$row["platitor"]."&nbsp";
					echo "</TD>";	
					echo"<TD colspan=\"1\" width=\"35%\" align=\"left\">";
					echo "&nbsp".$row["reprezentand"]."&nbsp";
					echo "</TD>";						
					echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "<INPUT TYPE=\"SUBMIT\" NAME=\"actiune\" id=\"button11\" VALUE=\"<".$row["id"].">\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
					echo "</TD>";
				}
				
				if ($row["tip_doc"] === "CHA" and $row["anulat"] <> 'X')
				{	
					echo "</FORM>";
					echo "<FORM NAME=\"form3\" ACTION=\"A21_listare_chit.php\" METHOD=\"POST\" onsubmit=\"target_popup13(this)\">";		
					include 'A21_param1.php';
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".substr($_POST["actiune"],2,5)."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA\">";
					
					echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "<INPUT TYPE=\"SUBMIT\" NAME=\"actiune\" id=\"button11\" VALUE=\"-".$row["id"]."-\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
					echo "</TD>";
					echo "</FORM>";
				}			
				else
				{
					echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "</TD>";
				}
				echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
				echo "&nbsp".$row["anulat"]."&nbsp";
				echo "</TD>";
				$i++;
			}
				
				echo "<TR>";
				echo "<TD>&nbsp</TD>";
				echo "</TR>";

				echo "<tr>";
			    echo "<td colspan=\"4\" align=\"right\">";
				echo "Total:";
				echo "</TD>";
			    echo "<td colspan=\"1\" align=\"center\">";
				echo $platit_tot;
				echo "</TD>";
				echo "</TR>";
				
				echo "<TR>";
				echo "<TD>&nbsp</TD>";
				echo "</TR>";
				
		echo "</form>";
		echo "</table>";	
		mysql_close($connection);
}

if ($_POST["actiune"]==="EVIDENTA ALTE DIVERSE VENITURI" 
		OR $_POST["actiune"]==="CONFIRM" AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DIVERSE"
		OR $_POST["actiune"]==="MODIFIC" AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DIVERSE"
		OR $_POST["actiune"]==="STERGE"  AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DIVERSE"
		
		OR $_POST["actiune"]==="INAPOI"  AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="PLA_D"
		OR $_POST["actiune"]==="INAPOI"  AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DEB_D"
		or substr($_POST["actiune"],0,4)==="CAUT" AND isset($_POST["tip_act_caut"]) and $_POST["tip_act_caut"]==="CAUTD")
{
			$wan2 = $_POST["an"]+1;

			echo "<CENTER>";
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<TR BGCOLOR=\"#4EAEF2\">";
			echo "<TD colspan=\"11\" class=\"style1\" height=\"25\" align=\"center\">";
			echo "<B> ".$_POST["den_aplic"]."</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<TR BGCOLOR=\"#A3D9FF\">";
			echo "<TD width=\"250\" class=\"style1\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
			echo "</TD>";
			echo "<TD width=\"160\" class=\"style1\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
			echo "</TD>";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "</table>";
			
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
			echo "<tr>";
			echo "<td colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "</table>";
				
			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
			
			echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup3(this)\">";
			include 'A21_param1.php';
		
			$wdenluna_sel=substr($_POST["luna_sel"],3,strlen($_POST["luna_sel"])-3);
			$wdengrp_sel=substr($_POST["grp_sel"],3,strlen($_POST["grp_sel"])-3);
			
			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			
			echo "<B>EVIDENTA ALTE DIVERSE VENITURI</B>";
		
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";
			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"50%\" border=0>";
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>LUNA:&nbsp<U>".$wdenluna_sel."</U>&nbsp&nbsp&nbsp&nbsp AN SCOLAR:&nbsp<U>".$_POST["an"]." - ".$wan2."</U></B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";

			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"30%; height:100%;\" border=0 align=\"right\">";
			echo "<TR>";
			echo "<TD align=\"right\" height=\"35\">";
			
			echo "<INPUT TYPE=\"SUBMIT\" class=\"noPrint\" NAME=\"actiune\" VALUE=\"ADAUG\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DIVERSE\">";

			if(isset($_POST["sel_codcopil"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
			}
			if(isset($_POST["sel_copilul"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
			}
			echo "</TD>";
			echo "</FORM>";
			
			echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" TARGET=\"win01\">";
			include 'A21_param1.php';
			echo "<TD align=\"left\" height=\"35\">";
			echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"INAPOI\">";
			
			if(isset($_POST["codparinte"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codparinte\" value=\"".$_POST["codparinte"]."\">";
			}
			if(isset($_POST["sel_codcopil"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
			}
			if(isset($_POST["sel_copilul"]))
			{
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
			}
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";
			
			
	IF ($_POST["actiune"]==="CONFIRM" and isset($_POST["tip_act"]) AND $_POST["tip_act"] === "DIVERSE")
	{
		include 'A21_param1.php';
	
			$wcodcopil = $_POST["codcopil"];
			$wnume=$_POST["nume_".$wcodcopil];
/*			
			$wprenume=$_POST["prenume_".$wcodcopil];
			$wparinte1=$_POST["parinte1"];
			$wtelefon1=$_POST["telefon1"];
			$wparinte2=$_POST["parinte2"];
			$wtelefon2=$_POST["telefon2"];
			$wparinte3=$_POST["parinte3"];
			$wtelefon3=$_POST["telefon3"];
			$wadresa=$_POST["adresa_p"];
*/
			$query="SELECT codgrp FROM copii where codgrp='99'";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			$row = mysql_fetch_array( $result);
			
			$query2="SELECT * FROM grupe where codgrp='99' and (t_val01 > 0 or t_val02 > 0 or t_val03 > 0
			 or t_val04 > 0 or t_val05 > 0 or t_val06 > 0 or t_val07 > 0 or t_val08 > 0 or t_val09 > 0 or t_val10 > 0 or t_val11 > 0 or t_val12 > 0)";
			$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());
		
		if(mysql_num_rows($result) == 0 AND mysql_num_rows($result2) == 0) 
		{			
			$query4="UPDATE grupe set t_val01='0', t_val02='0', t_val03='0', ";
			$query4=$query4."t_val04='0', t_val05='0', t_val06='0', t_val07='0', ";
			$query4=$query4."t_val08='0', t_val09='0', t_val10='0', t_val11='0', ";
			$query4=$query4."t_val12='0' WHERE codgrp='99'";
			$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());
		}	
			
		$query0="SELECT codgrp,codcopil FROM copii where codgrp='99' and codcopil=(select max(codcopil) from copii where codgrp='99') order by codcopil";
		$result0=mysql_query($query0) or die("Interogare esuata: ".mysql_error());	
		$row0 = mysql_fetch_array( $result0);
			
		IF ($_POST["codcopil"] <> $row0["codcopil"])
		{		
			$query3="INSERT INTO copii (codgrp,codcopil,nume)";
			$query3=$query3."VALUES ('99',\"".$wcodcopil."\",\"".$wnume."\")";
			$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());	
		}
		else
		{
			echo '<script type="text/javascript">';
			echo 'alert("Datele au fost actualizate. Reluati!");';
			echo '</script>';
		}
	}
	
	if ($_POST["actiune"]==="MODIFIC" and isset($_POST["tip_act"]) AND $_POST["tip_act"] === "DIVERSE")
	{	
		include 'A21_param1.php';
		
			$wcodcopil = $_POST["codcopil"];
			$wnume=$_POST["nume_".$wcodcopil];
/*			
			$wprenume=$_POST["prenume_".$wcodcopil];
			$wparinte1=$_POST["parinte1"];
			$wtelefon1=$_POST["telefon1"];
			$wparinte2=$_POST["parinte2"];
			$wtelefon2=$_POST["telefon2"];
			$wparinte3=$_POST["parinte3"];
			$wtelefon3=$_POST["telefon3"];
			$wadresa=$_POST["adresa_p"];
*/			
			$query4="UPDATE copii set nume=\"".$wnume."\" WHERE codcopil = \"".$_POST["codcopil"]."\"";
			$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());
	}
	
	if ($_POST["actiune"]==="STERGE" and isset($_POST["tip_act"]) AND $_POST["tip_act"] === "DIVERSE")
	{
		include 'A21_param1.php';
		
		$wcodcopil = $_POST["codcopil"];
		
		$query0="SELECT * FROM copii WHERE codcopil=\"".$wcodcopil."\" AND (d_val00 > 0 or d_val01 > 0 or d_val02 > 0 or d_val03 > 0
		 or d_val04 > 0 or d_val05 > 0 or d_val06 > 0 or d_val07 > 0 or d_val08 > 0 or d_val09 > 0 or d_val10 > 0 or d_val11 > 0 or d_val12 > 0  
		 or p_val01 > 0 or p_val02 > 0 or p_val03 > 0 or p_val04 > 0 or p_val05 > 0 or p_val06 > 0 or p_val07 > 0 or p_val08 > 0 or p_val09 > 0 or p_val10 > 0 or p_val11 > 0 or p_val12 > 0
		 or r_val01 > 0 or r_val02 > 0 or r_val03 > 0 or r_val04 > 0 or r_val05 > 0 or r_val06 > 0 or r_val07 > 0 or r_val08 > 0 or r_val09 > 0 or r_val10 > 0 or r_val11 > 0 or r_val12 > 0)";
		$result0=mysql_query($query0) or die("Interogare esuata: ".mysql_error());	
		$row0=mysql_fetch_array($result0);
		$total0=mysql_num_rows($result0);

		IF ($total0 == 0)
		{
			$query4="DELETE FROM copii WHERE codcopil = \"".$_POST["codcopil"]."\"";
			$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());
			
			$query5="DELETE FROM chitante WHERE codcopil = \"".$_POST["codcopil"]."\"";
			$result5=mysql_query($query5) or die("Interogare esuata: ".mysql_error());				
		}		
		ELSE
		{							
			echo '<script type="text/javascript">alert("Tip venit: '.$row0["codcopil"].' - '.$row0['nume'].' are valori pe PLATI!\n Stergere esuata.");</script>';
		}
	}

	
	
// *****************				
		if(isset($_POST["sel_codcopil"]))
		{
			$wsel_codcopil=$_POST["sel_codcopil"];
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
		}
		else
		{
			$wsel_codcopil="";
		}
		if(isset($_POST["sel_copilul"]))
		{
			$wsel_copilul=$_POST["sel_copilul"];
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
		}
		else
		{
			$wsel_copilul="";
		}	
			
		echo "<TABLE cellSpacing=0 cellPadding=0 width=\"90%\" border=0>";
		echo "<TR>";
			
		echo "<TD colspan=\"1\" align=\"left\">";  
		echo "<INPUT name=\"sel_codcopil\" SIZE=\"2\" type=\"text\" VALUE=\"".$wsel_codcopil."\">";
		echo "</TD>";
		echo "<TD colspan=\"1\" align=\"left\">";  
		echo "<INPUT name=\"sel_copilul\" type=\"text\" VALUE=\"".$wsel_copilul."\">";
		echo "</TD>";
		echo "<TD colspan=\"1\" align=\"left\" height=\"30px\">";  
		echo "<INPUT TYPE=\"SUBMIT\" name=\"actiune\" class=\"noPrint\" VALUE=\"CAUT\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act_caut\" VALUE=\"CAUTD\">";
		echo "</TD>";
		echo "</TR>";
	
// *******************				

				
// ************************************
				if($_POST["actiune"]==="CAUT" or isset($_POST["sel_codcopil"]) or isset($_POST["sel_copilul"]))
				{
					$wcaut_codcopil=strtoupper(trim($_POST["sel_codcopil"]));
					$wlen_codcopil=strlen($wcaut_codcopil);
					$wcaut_copilul=strtoupper(trim($_POST["sel_copilul"]));
					$wlen_copilul=strlen($wcaut_copilul);
					
					$query="SELECT * FROM copii WHERE codgrp='99'";
					if ($wlen_codcopil<>0)
					{
						$query=$query."  and substr(upper(codcopil),1,".$wlen_codcopil.")=\"".$wcaut_codcopil."\"";
					}
					if ($wlen_copilul<>0)
					{
						//$query=$query."  and substr(upper(concat(nume,' ',prenume)),1,".$wlen_copilul.")=\"".$wcaut_copilul."\"";
						$query=$query."  and substr(upper(nume),1,".$wlen_copilul.")=\"".$wcaut_copilul."\"";
					}
					
					$query=$query."  order by nume,prenume,codcopil";
				}
				else
				{
					$query="SELECT * FROM copii WHERE codgrp='99' order by nume,prenume,codcopil";
				}	
				$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());	
// ************************************
		
		echo "</FORM>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";
			
			echo 	"<TH align=\"center\" width=\"4%\" class=\"td35\">ID</TH>";					
			echo	"<TH align=\"center\" width=\"14%\"  class=\"td35\">Tip Venit</TH>";	
			echo	"<TH align=\"center\" width=\"6%\" class=\"td35\">TipReg</TH>";		
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">PREC</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">SEP</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">OCT</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">NOI</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">DEC</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IAN</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">FEB</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAR</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">APR</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAI</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUN</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUL</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">AUG</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td39\">TOTAL</TH>";
			
			echo "</TR>";
		
		$i=0;
		$debit_tot=0;
		$wlu=substr($_POST["luna_sel"],0,2);
		while($row = mysql_fetch_array( $result))	
		{ 	
			$debit_tot = $row["d_val00"] + $row["d_val01"] + $row["d_val02"] + $row["d_val03"] + $row["d_val04"] + $row["d_val05"] + $row["d_val06"] + $row["d_val07"] + $row["d_val08"] + $row["d_val09"] + $row["d_val10"] + $row["d_val11"] + $row["d_val12"];
			$platit_tot = $row["p_val01"] + $row["p_val02"] + $row["p_val03"] + $row["p_val04"] + $row["p_val05"] + $row["p_val06"] + $row["p_val07"] + $row["p_val08"] + $row["p_val09"] + $row["p_val10"] + $row["p_val11"] + $row["p_val12"];
			//$rest_tot = $debit_tot - $platit_tot;
			$rest_tot = $debit_tot + $platit_tot;
			
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
		
		echo "<TD width=\"2%\" height=\"30px\" align=\"center\">";
				
		echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup3(this)\">";
		include 'A21_param1.php';	

		echo "<input type=\"submit\" name=\"actiune\" class=\"noPrint9\" value='<".$row["codcopil"].">'>";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DIVERSE\">";
		
		if(isset($_POST["sel_codcopil"]))
		{
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
		}
		if(isset($_POST["sel_copilul"]))
		{
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
		}
		echo "</FORM>";
		
				echo "</TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "&nbsp".trim($row["nume"])." ".trim($row["prenume"])."&nbsp";
				echo "</TD>";
				echo"<TD width=\"1%\" height=\"30px\" align=\"center\">";
				
		echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup4(this)\">";
		include 'A21_param1.php';
			
		echo "<input type=\"submit\" DISABLED = \"DISABLED\" class=\"noPrint6_1\" NAME=\"actiune\" value=\"D-".$row["codcopil"]."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DEB_D\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$row["nume"]."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$row["prenume"]."\">";
		
		if(isset($_POST["sel_codcopil"]))
		{
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
		}
		if(isset($_POST["sel_copilul"]))
		{
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
		}
		echo "</FORM>";
		
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val00"]."&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val09"]."&nbsp";
				if($wlu==="09")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val10"]."&nbsp";
				if($wlu==="10")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val11"]."&nbsp";
				if($wlu==="11")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val12"]."&nbsp";
				if($wlu==="12")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val01"]."&nbsp";
				if($wlu==="01")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val02"]."&nbsp";
				if($wlu==="02")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val03"]."&nbsp";
				if($wlu==="03")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val04"]."&nbsp";
				if($wlu==="04")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val05"]."&nbsp";
				if($wlu==="05")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val06"]."&nbsp";
				if($wlu==="06")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val07"]."&nbsp";
				if($wlu==="07")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"]+$row["d_val07"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val08"]."&nbsp";
				if($wlu==="08")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"]+$row["d_val07"]+$row["d_val08"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $debit_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
		
				echo "<TD width=\"3%\" align=\"center\"> </TD>";
				echo"<TD width=\"13%\" align=\"left\">";
				echo " ";
				echo "</TD>";
				echo"<TD width=\"1%\" height=\"30px\" align=\"center\">";
				
		echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\" onsubmit=\"target_popup10(this)\">";
		include 'A21_param1.php';
			
		echo "<input type=\"submit\" class=\"noPrint6\" NAME=\"actiune\" value=\"P-".$row["codcopil"]."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA_D\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$row["nume"]."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$row["prenume"]."\">";

		if(isset($_POST["sel_codcopil"]))
		{
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
		}
		if(isset($_POST["sel_copilul"]))
		{
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
		}
		echo "</FORM>";
		
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo " ";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val09"]."&nbsp";
				if($wlu==="09")
				{
					$platit_ln=$row["p_val09"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val10"]."&nbsp";
				if($wlu==="10")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val11"]."&nbsp";
				if($wlu==="11")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val12"]."&nbsp";
				if($wlu==="12")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val01"]."&nbsp";
				if($wlu==="01")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val02"]."&nbsp";
				if($wlu==="02")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val03"]."&nbsp";
				if($wlu==="03")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val04"]."&nbsp";
				if($wlu==="04")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val05"]."&nbsp";
				if($wlu==="05")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val06"]."&nbsp";
				if($wlu==="06")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val07"]."&nbsp";
				if($wlu==="07")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"]+$row["p_val07"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val08"]."&nbsp";
				if($wlu==="08")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"]+$row["p_val07"]+$row["p_val08"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $platit_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
//				$i++;
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
		
				echo "<TD width=\"3%\" align=\"center\"> </TD>";
				echo"<TD width=\"13%\" align=\"left\">";
				echo " ";
				echo "</TD>";
				echo"<TD width=\"1%\" height=\"30px\" align=\"center\">";
				echo "<B>REST_PL</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo " ";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="09")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val09"]."&nbsp";
				if($wlu==="09")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="10")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val10"]."&nbsp";
				if($wlu==="10")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="11")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val11"]."&nbsp";
				if($wlu==="11")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="12")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val12"]."&nbsp";
				if($wlu==="12")
				{
					echo "</B>";
				}
				echo "</TD>";
								echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="01")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val01"]."&nbsp";
				if($wlu==="01")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="02")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val02"]."&nbsp";
				if($wlu==="02")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="03")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val03"]."&nbsp";
				if($wlu==="03")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="04")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val04"]."&nbsp";
				if($wlu==="04")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="05")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val05"]."&nbsp";
				if($wlu==="05")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="06")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val06"]."&nbsp";
				if($wlu==="06")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="07")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val07"]."&nbsp";
				if($wlu==="07")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				if($wlu==="08")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val08"]."&nbsp";
				if($wlu==="08")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $rest_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				$i++;
		}
						
		echo "</form>";
		echo "</table>";	

		mysql_close($connection);
}

if ($_POST["actiune"]==="ADAUG" and isset($_POST["tip_act"]) and $_POST["tip_act"]==="DIVERSE")
{
	echo "<CENTER>";
	
		echo "<FORM NAME=\"form2\" ACTION=\"A21_copii.php\" METHOD=\"POST\" TARGET=\"win01\"";
		include 'A21_param1.php';

			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		

			$query="SELECT codgrp,codcopil FROM copii where codgrp='99' and codcopil=(select max(codcopil) from copii where codgrp='99') order by codcopil";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			
			if(mysql_num_rows($result) == 0) 
			{
				$wcodcopil="9901";
			}
			else
			{
				$row = mysql_fetch_array($result);
				$wcodcopil = $row["codcopil"] + 1;
			}
			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>ADAUGARE TIP VENIT</B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";
			
			echo "<TABLE cellSpacing=0 cellPadding=0 height=\"100%\" width=\"80%\" border=0>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";

			echo "<tr>";
			echo "<td colspan=\"2\">ID:</td>";
			echo "<td colspan=\"2\">";
			echo "".$wcodcopil."";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$wcodcopil."\">";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td colspan=\"2\">Tip venit:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"32\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"nume_".$wcodcopil."\" VALUE=\"\">";
			echo "</td>";
			echo "</tr>";
			echo "</table>";
			
			include 'A21_param1.php';
			echo "<TABLE cellSpacing=0 align=\"right\" cellPadding=0 width=\"50%; height:15%;\" border=0>";
			echo "<TR>";
			echo "<TD>&nbsp</TD>";
			echo "</TR>";
			echo "<tr>";
		    echo "<td width=\"15%\" height=\"35\" align=\"right\">";
			echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"CONFIRM\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DIVERSE\">";
			echo "</td>";
			echo "<td width=\"15%\" height=\"35\" align=\"left\">";
			echo "<input name=\"button\" type=\"button\" id=\"button10\" value=\"RENUNT\" onClick=\"javascript:window.close()\">";
			echo "</td>";
			echo  "</tr>";
			echo "</TABLE>";
		
			echo "</form>";
			echo "</TABLE>";
			
		mysql_close($connection);
		
}

if (substr($_POST["actiune"],0,1)==="<" AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DIVERSE")
{
	echo "<CENTER>";
	
		echo "<FORM NAME=\"form5\" ACTION=\"A21_copii.php\" METHOD=\"POST\" TARGET=\"win01\"";
		include 'A21_param1.php';

			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
			
			$query="SELECT codcopil,nume FROM copii where codcopil=\"".substr($_POST["actiune"],1,strpos($_POST["actiune"],'>')-1)."\" order by codcopil";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());		

			$row = mysql_fetch_array( $result ); 
			$wcodcopil = $row["codcopil"];

			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>EDITARE TIP VENIT</B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";

			echo "<TABLE cellSpacing=0 cellPadding=0 height=\"100%\" width=\"80%\" border=0>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";

			echo "<tr>";
			echo "<td colspan=\"2\">ID:</td>";
			echo "<td colspan=\"2\">";
			echo "".$wcodcopil."";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$wcodcopil."\">";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td colspan=\"2\">Tip venit:</td>";
			echo "<td colspan=\"2\">";
			echo "<INPUT TYPE=\"TEXT\" size=\"32\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" class=\"text13\" NAME=\"nume_".$wcodcopil."\" VALUE=\"".$row["nume"]."\">";
			echo "</td>";
			echo "</tr>";
			echo "</table>";
			
			include 'A21_param1.php';
			echo "<TABLE cellSpacing=0 align=\"center\" cellPadding=0 width=\"80%; height:15%;\" border=0>";
			echo "<TR>";
			echo "<TD>&nbsp</TD>";
			echo "</TR>";
			echo "<tr>";
			echo "<td width=\"1%\" height=\"35px\" align=\"left\">";
			echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" onClick=\"return confirm_stergere_c()\" value=\"STERGE\">";	
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DIVERSE\">";
			echo "</TD>";
		    echo "<td width=\"1%\" height=\"35px\" align=\"right\">";
			echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"MODIFIC\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DIVERSE\">";
			echo "</TD>";
		    echo "<td width=\"1%\" height=\"35px\" align=\"left\">";
			echo "<input name=\"button\" type=\"button\" id=\"button10\" value=\"RENUNT\" onClick=\"javascript:window.close()\">";
			echo "</td>";
			echo  "</tr>";
			echo "</TABLE>";
			echo "</FORM>";
			
		mysql_close($connection);
		
}

if (substr($_POST["actiune"],0,2)==="D-" AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DEB_D" 
	OR $_POST["actiune"]==="CONFIRM"  AND isset($_POST["tip_act"]) and $_POST["tip_act"]==="DEB_D")
{
	echo "<BODY id=\"bg_deb\">";
	echo "<CENTER>";  

	$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
	$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
	$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
	
			echo "<FORM NAME=\"form3\" id=\"form_confirm\" ACTION=\"A21_copii.php\" METHOD=\"POST\" TARGET=\"win01\">";
			include 'A21_param1.php';
		
			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"30%; height:100%;\" border=0 align=\"right\">";
			echo "<TR>";
			echo "<TD align=\"right\" height=\"35\">";
			echo "<INPUT TYPE=\"SUBMIT\" class=\"noPrint\" NAME=\"actiune\" onClick=\"javascript:setTimeout('window.close()',300);\" VALUE=\"INAPOI\">";
		//	echo "<INPUT TYPE=\"SUBMIT\" class=\"noPrint\" NAME=\"actiune\"  VALUE=\"INAPOI\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DEB_D\">";
			echo "</TD>";
			echo "</TR>";
			echo "</table>";
			echo "</form>";
			
		echo "<FORM NAME=\"form3\" id=\"form_confirm\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
		include 'A21_param1.php';

		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".substr($_POST["actiune"],2,5)."\">";	
		
		$query3="SELECT * FROM grupe WHERE codgrp='99'";
		$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());
		$row3 = mysql_fetch_array( $result3);
		
		$w_t_val01=$row3["t_val01"];
		$w_t_val02=$row3["t_val02"];
		$w_t_val03=$row3["t_val03"];
		$w_t_val04=$row3["t_val04"];
		$w_t_val05=$row3["t_val05"];
		$w_t_val06=$row3["t_val06"];
		$w_t_val07=$row3["t_val07"];
		$w_t_val08=$row3["t_val08"];
		$w_t_val09=$row3["t_val09"];
		$w_t_val10=$row3["t_val10"];
		$w_t_val11=$row3["t_val11"];
		$w_t_val12=$row3["t_val12"];
		
		$query="SELECT * FROM copii where codcopil=\"".substr($_POST["actiune"],2,5)."\"";
		$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());		
		$row = mysql_fetch_array( $result);	
	
	IF ($_POST["actiune"]==="CONFIRM" and isset($_POST["tip_act"]) AND $_POST["tip_act"] === "DEB_D")
	{
		echo "<FORM NAME=\"form3\" id=\"form_confirm\" ACTION=\"A21_copii.php\" METHOD=\"POST\" >";
		include 'A21_param1.php';
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$_POST["codcopil"]."\">";
		
		$query2="SELECT * FROM copii ";
		$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());
	//	$row = mysql_fetch_array( $result);
	
		$i=0;
		while ($row2 = mysql_fetch_array( $result2))
		{			
			$query="SELECT * FROM copii WHERE codcopil=\"".$_POST["codcopil"]."\"";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			$row = mysql_fetch_array( $result);
		
			$w_z_val01=$_POST["z_val01"];
			$w_z_val02=$_POST["z_val02"];
			$w_z_val03=$_POST["z_val03"];
			$w_z_val04=$_POST["z_val04"];
			$w_z_val05=$_POST["z_val05"];
			$w_z_val06=$_POST["z_val06"];
			$w_z_val07=$_POST["z_val07"];
			$w_z_val08=$_POST["z_val08"];
			$w_z_val09=$_POST["z_val09"];
			$w_z_val10=$_POST["z_val10"];
			$w_z_val11=$_POST["z_val11"];
			$w_z_val12=$_POST["z_val12"];
		
			$w_d_val00=$_POST["d_val00"];

			IF ($w_t_val01 === "0")
			{
			$w_d_val01 = 0;
			}
			else
			{
			$w_d_val01=$w_z_val01 * $w_t_val01;
			}
			IF ($w_t_val02 === "0")
			{
			$w_d_val02 = 0;
			}
			else
			{
			$w_d_val02=$w_z_val02 * $w_t_val02;
			}
			IF ($w_t_val03 === "0")
			{
			$w_d_val03 = 0;
			}
			else
			{
			$w_d_val03=$w_z_val03 * $w_t_val03;
			}
			IF ($w_t_val04 === "0")
			{
			$w_d_val04 = 0;
			}
			else
			{
			$w_d_val04=$w_z_val04 * $w_t_val04;
			}
			IF ($w_t_val05 === "0")
			{
			$w_d_val05 = 0;
			}
			else
			{
			$w_d_val05=$w_z_val05 * $w_t_val05;
			}
			IF ($w_t_val06 === "0")
			{
			$w_d_val06 = 0;
			}
			else
			{
			$w_d_val06=$w_z_val06 * $w_t_val06;
			}
			IF ($w_t_val07 === "0")
			{
			$w_d_val07 = 0;
			}
			else
			{
			$w_d_val07=$w_z_val07 * $w_t_val07;
			}
			IF ($w_t_val08 === "0")
			{
			$w_d_val08 = 0;
			}
			else
			{
			$w_d_val08=$w_z_val08 * $w_t_val08;
			}
			IF ($w_t_val09 === "0")
			{
			$w_d_val09 = 0;
			}
			else
			{
			$w_d_val09=$w_z_val09 * $w_t_val09;
			}
			IF ($w_t_val10 === "0")
			{
			$w_d_val10 = 0;
			}
			else
			{
			$w_d_val10=$w_z_val10 * $w_t_val10;
			}
			IF ($w_t_val11 === "0")
			{
			$w_d_val11 = 0;
			}
			else
			{
			$w_d_val11=$w_z_val11 * $w_t_val11;
			}
			IF ($w_t_val12 === "0")
			{
			$w_d_val12 = 0;
			}
			else
			{
			$w_d_val12=$w_z_val12 * $w_t_val12;
			}
			
			$w_p_val01=$row["p_val01"];
			$w_p_val02=$row["p_val02"];
			$w_p_val03=$row["p_val03"];
			$w_p_val04=$row["p_val04"];
			$w_p_val05=$row["p_val05"];
			$w_p_val06=$row["p_val06"];
			$w_p_val07=$row["p_val07"];
			$w_p_val08=$row["p_val08"];
			$w_p_val09=$row["p_val09"];
			$w_p_val10=$row["p_val10"];
			$w_p_val11=$row["p_val11"];
			$w_p_val12=$row["p_val12"];

/*
			$w_r_val09=($w_d_val00+$w_d_val09)-$w_p_val09;
			$w_r_val10=($w_d_val00+$w_d_val09+$w_d_val10)-($w_p_val09+$w_p_val10);
			$w_r_val11=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11)-($w_p_val09+$w_p_val10+$w_p_val11);
			$w_r_val12=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12);
			$w_r_val01=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01);
			$w_r_val02=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02);
			$w_r_val03=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03);
			$w_r_val04=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04);
			$w_r_val05=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05);
			$w_r_val06=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06);
			$w_r_val07=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07);
			$w_r_val08=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08)-($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08);
*/
			$w_r_val09=($w_d_val00+$w_d_val09)+$w_p_val09;
			$w_r_val10=($w_d_val00+$w_d_val09+$w_d_val10)+($w_p_val09+$w_p_val10);
			$w_r_val11=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11)+($w_p_val09+$w_p_val10+$w_p_val11);
			$w_r_val12=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12);
			$w_r_val01=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01);
			$w_r_val02=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02);
			$w_r_val03=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03);
			$w_r_val04=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04);
			$w_r_val05=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05);
			$w_r_val06=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06);
			$w_r_val07=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07);
			$w_r_val08=($w_d_val00+$w_d_val09+$w_d_val10+$w_d_val11+$w_d_val12+$w_d_val01+$w_d_val02+$w_d_val03+$w_d_val04+$w_d_val05+$w_d_val06+$w_d_val07+$w_d_val08)+($w_p_val09+$w_p_val10+$w_p_val11+$w_p_val12+$w_p_val01+$w_p_val02+$w_p_val03+$w_p_val04+$w_p_val05+$w_p_val06+$w_p_val07+$w_p_val08);
			
			
			$query4="UPDATE copii set z_val01=\"".$w_z_val01."\", z_val02=\"".$w_z_val02."\", z_val03=\"".$w_z_val03."\", ";
			$query4=$query4."z_val04=\"".$w_z_val04."\", z_val05=\"".$w_z_val05."\", z_val06=\"".$w_z_val06."\", z_val07=\"".$w_z_val07."\", ";
			$query4=$query4."z_val08=\"".$w_z_val08."\", z_val09=\"".$w_z_val09."\", z_val10=\"".$w_z_val10."\", z_val11=\"".$w_z_val11."\", ";
			$query4=$query4."z_val12=\"".$w_z_val12."\", ";
			$query4=$query4."d_val00=\"".$w_d_val00."\", d_val01=\"".$w_d_val01."\", d_val02=\"".$w_d_val02."\", d_val03=\"".$w_d_val03."\", ";
			$query4=$query4."d_val04=\"".$w_d_val04."\", d_val05=\"".$w_d_val05."\", d_val06=\"".$w_d_val06."\", d_val07=\"".$w_d_val07."\", ";
			$query4=$query4."d_val08=\"".$w_d_val08."\", d_val09=\"".$w_d_val09."\", d_val10=\"".$w_d_val10."\", d_val11=\"".$w_d_val11."\", ";
			$query4=$query4."d_val12=\"".$w_d_val12."\", ";
			$query4=$query4."r_val01=\"".$w_r_val01."\", r_val02=\"".$w_r_val02."\", r_val03=\"".$w_r_val03."\", ";
			$query4=$query4."r_val04=\"".$w_r_val04."\", r_val05=\"".$w_r_val05."\", r_val06=\"".$w_r_val06."\", r_val07=\"".$w_r_val07."\", ";
			$query4=$query4."r_val08=\"".$w_r_val08."\", r_val09=\"".$w_r_val09."\", r_val10=\"".$w_r_val10."\", r_val11=\"".$w_r_val11."\", ";
			$query4=$query4."r_val12=\"".$w_r_val12."\" ";
			$query4=$query4."WHERE codcopil = \"".$_POST["codcopil"]."\"";
			$result4=mysql_query($query4) or die("Interogare esuata: ".mysql_error());	

			
			$query="SELECT * FROM copii WHERE codcopil=\"".$_POST["codcopil"]."\"";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
			$row = mysql_fetch_array( $result);	
		}		
	//	echo "</form>";
	}			
		
			
			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";			
			echo "<TR>";
			echo "<TD colspan=\"32\" align=\"center\" class=\"td_print2\">";
			echo "<B>EDITARE DEBITE</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";
			
			echo 	"<TH align=\"center\" width=\"2%\" class=\"td35\">ID</TH>";					
			echo	"<TH align=\"center\" width=\"10%\"  class=\"td35\">Tip Venit</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">&nbsp</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">PREC</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">SEP</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">OCT</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">NOI</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">DEC</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IAN</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">FEB</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAR</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">APR</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAI</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUN</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUL</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">AUG</TH>";
			echo	"<TH align=\"center\" width=\"3%\" class=\"td39\">TOTAL</TH>";			
			echo "</TR>";	

			$debit_tot = $row["d_val00"] + $row["d_val01"] + $row["d_val02"] + $row["d_val03"] + $row["d_val04"] + $row["d_val05"] + $row["d_val06"] + $row["d_val07"] + $row["d_val08"] + $row["d_val09"] + $row["d_val10"] + $row["d_val11"] + $row["d_val12"];
			
			echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
		
				echo "<TD width=\"2%\" height=\"30px\" align=\"center\">";
				echo $row["codcopil"];
				echo "</TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "&nbsp".trim($row["nume"])." ".trim($row["prenume"])."&nbsp";
				echo "</TD>";
				echo "<TD width=\"2%\" align=\"center\">";
				echo "Nr. zile prezent";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">&nbsp</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val09\" VALUE=".$row["z_val09"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val10\" VALUE=".$row["z_val10"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val11\" VALUE=".$row["z_val11"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val12\" VALUE=".$row["z_val12"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val01\" VALUE=".$row["z_val01"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val02\" VALUE=".$row["z_val02"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val03\" VALUE=".$row["z_val03"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val04\" VALUE=".$row["z_val04"].">";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val05\" VALUE=".$row["z_val05"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val06\" VALUE=".$row["z_val06"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val07\" VALUE=".$row["z_val07"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" size=\"2\"  onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey(event)\" class=\"text1\" NAME=\"z_val08\" VALUE=".$row["z_val08"].">";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp</B></TD>";
				echo "</TR>";

				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
				echo "<TD width=\"2%\" height=\"30px\" align=\"center\">";
				echo "</TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "</TD>";
				echo "<TD width=\"2%\" align=\"center\">";
				echo "Tarif / zi";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">&nbsp</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val09."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val10."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val11."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val12."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val01."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val02."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val03."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val04."&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "".$w_t_val05."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val06."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val07."&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "".$w_t_val08."&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp</TD>";
				echo "</TR>";
				echo "<TR>";
				echo "<TD colspan=\"17\">";
				echo "<hr width=\"100%\">";
				echo "</TD>";
				echo "</TR>";
				echo "<TR>";
				echo "<TD width=\"2%\" height=\"30px\" align=\"center\">";				
				echo "</TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "</TD>";
				echo "<TD width=\"2%\" align=\"center\">";
				echo "<B>TOTAL:&nbsp</B>";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<INPUT TYPE=\"TEXT\" style=\"font-weight:bold;\" size=\"2\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey1(event)\" class=\"text1\" NAME=\"d_val00\" VALUE=".$row["d_val00"].">";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val09"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val10"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val11"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val12"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val01"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val02"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val03"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val04"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>".$row["d_val05"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val06"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val07"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"2%\" align=\"right\">";
				echo "<B>".$row["d_val08"]."</B>&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $debit_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				echo "</B>";
				
				echo "<TR>";
				echo "<TD>&nbsp</TD>";
				echo "</TR>";
				echo "<tr>";
			    echo "<td colspan=\"15\" width=\"15%\" height=\"35\" align=\"right\">";
			//	echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"CONFIRM\">";
				echo "<input type=\"submit\" name=\"actiune\" id=\"button10\" value=\"CONFIRM\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"DEB_D\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_actiune\" VALUE=\"CONF\">";
				echo "</td>";
				echo "<td  colspan=\"2\" width=\"15%\" height=\"35\" align=\"left\">";
				if (!isset($_POST["tip_actiune"]))
				{	
					echo "<input name=\"button\" type=\"button\" id=\"button10_2\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"RENUNT\" >";				
				}
				else
				{
					echo "<input name=\"button\" type=\"button\" disabled=\"disabled\" id=\"button10_2\" onMouseUp=\"javascript:setTimeout('window.close()',300);\" value=\"RENUNT\" >";	
				}			
				echo "</td>";
				echo  "</tr>";			

		echo "</form>";
		echo "</table>";	
		mysql_close($connection);
}

if (substr($_POST["actiune"],0,2)==="P-" and isset($_POST["tip_act"]) and $_POST["tip_act"]==="PLA_D")
{
	echo "<BODY id=\"bg_plati\">";
	echo "<CENTER>";

			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
			
			$query="SELECT * FROM chitante where codcopil=\"".substr($_POST["actiune"],2,5)."\" order by tip_doc,nr_doc,data_doc";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());		
		
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD colspan=\"6\" align=\"left\" class=\"td_print2\">";
			echo "<B>PLATI</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD colspan=\"6\" align=\"left\">";
			echo "<B>".substr($_POST["actiune"],2,5)." - ";
			echo "&nbsp".trim($_POST["nume"])." ".trim($_POST["prenume"])."&nbsp";
			echo "</B></TD>";
			echo "</TR>";
			
		echo "<FORM NAME=\"form3\" ACTION=\"A21_editare_chit_div.php\" METHOD=\"POST\" onsubmit=\"target_popup10(this)\">";
		include 'A21_param1.php';
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".substr($_POST["actiune"],2,5)."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA_D\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
		echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";

		echo "<TR>";
		echo "<TD colspan=\"8\" height=\"35\" align=\"right\">";
		echo "<INPUT TYPE=\"button\" id=\"button11\" NAME=\"actiune\" VALUE=\"INAPOI\" onClick=\"javascript:window.close()\">";
		echo "</TD>";
		echo "</TR>";				
		echo "<TR>";
		echo "<TD colspan=\"8\" height=\"35\" align=\"right\">";
		echo "<INPUT TYPE=\"SUBMIT\" NAME=\"actiune\" id=\"button11\" VALUE=\"ADAUG\">";
		echo "</TD>";
		echo "</TR>";
		echo "<TR>";
		echo "<TD>";
		echo "&nbsp";
		echo "</TR>";
		echo "<TR>";
		echo "<TD>";
		echo "&nbsp";
		echo "</TD>";
		echo "</TR>";
		//echo "</FORM>";
		
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";			
			echo    "<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Nrc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Tip</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"20%\" class=\"td35\">Nr doc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"20%\" class=\"td35\">Data doc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Suma</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"30%\" class=\"td35\">Platitor</TH>";
			echo    "<TH colspan=\"1\" align=\"center\" width=\"15%\" class=\"td35\">Editare</TH>";		
			echo    "<TH colspan=\"1\" align=\"center\" width=\"15%\" class=\"td35\">Listare</TH>";
			echo    "<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td39\">Anulat</TH>";			
			echo "</TR>";
			$platit_tot=0;
			$i=0;
			while ($row = mysql_fetch_array( $result))
			{
				echo "<FORM NAME=\"form3\" ACTION=\"A21_editare_chit_div.php\" METHOD=\"POST\" onsubmit=\"target_popup10(this)\">";
				include 'A21_param1.php';
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".substr($_POST["actiune"],2,5)."\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA_D\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
				
				$data_doc = date("d-m-Y", strtotime($row["data_doc"]));
				
				if ($row["anulat"] <> 'X')
				{				
					$platit_tot = $platit_tot+$row["val_doc"];
				}
			
				if ($i-floor($i/2)*2==0)
				{
					echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
				}
				else
				{
					echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
				}
		 
				echo "<TD colspan=\"1\" width=\"10%\" height=\"25px\" align=\"center\">",$i+1,"</TD>";
				echo"<TD colspan=\"1\" width=\"10%\" align=\"center\">";
				echo "&nbsp".$row["tip_doc"]."&nbsp";
				echo "</TD>";
				echo"<TD colspan=\"1\" width=\"20%\" align=\"center\">";
				if($row["tip_doc"]==="CHA")
				{
					echo "&nbsp".$row["serie_doc"]."_".$row["nr_doc"]."&nbsp";
				}
				else
				{
					echo "&nbsp".$row["nr_doc"]."&nbsp";
				}
				echo "</TD>";
				echo"<TD colspan=\"1\" width=\"20%\" align=\"center\">";
				echo "&nbsp".$data_doc."&nbsp";
				echo "</TD>";

				
				if ($row["anulat"] === 'X')
				{
					echo"<TD colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "0&nbsp(".$row["val_doc"].")&nbsp";
					echo "</TD>";
					echo "<TD colspan=\"1\" width=\"30%\" align=\"left\">";
					echo "&nbsp".$row["platitor"]."&nbsp";
					echo "</TD>";
					//echo "<td colspan=\"1\" width=\"15%\" align=\"center\">";
					//echo "</TD>";
					echo "<td colspan=\"1\" width=\"15%\" align=\"center\">";
					echo "<INPUT TYPE=\"SUBMIT\" DISABLED=\"DISABLED\" NAME=\"actiune\" id=\"button11_2\" VALUE=\"\">";
					echo "</TD>";
				}
				else
				{
					echo"<TD colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "&nbsp".$row["val_doc"]."&nbsp";
					echo "</TD>";
					echo "<TD colspan=\"1\" width=\"30%\" align=\"left\">";
					echo "&nbsp".$row["platitor"]."&nbsp";
					echo "</TD>";					
					echo "<td colspan=\"1\" width=\"15%\" align=\"center\">";
					echo "<INPUT TYPE=\"SUBMIT\" NAME=\"actiune\" id=\"button11\" VALUE=\"<".$row["id"].">\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
					echo "</TD>";
				}
				
				if ($row["tip_doc"] === "CHA" and $row["anulat"] <> 'X')
				{	
					echo "</FORM>";
					echo "<FORM NAME=\"form3\" ACTION=\"A21_listare_chit_div.php\" METHOD=\"POST\" onsubmit=\"target_popup13(this)\">";		
					include 'A21_param1.php';
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".substr($_POST["actiune"],2,5)."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA_D\">";
					
					echo "<td colspan=\"1\" width=\"15%\" align=\"center\">";
					echo "<INPUT TYPE=\"SUBMIT\" NAME=\"actiune\" id=\"button11\" VALUE=\"-".$row["id"]."-\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
					echo "</TD>";
					echo "</FORM>";
				}			
				else
				{
					//echo "<td colspan=\"1\" width=\"15%\" align=\"center\">";
					//echo "</TD>";
					echo "<td colspan=\"1\" width=\"15%\" align=\"center\">";
					echo "<INPUT TYPE=\"SUBMIT\" DISABLED=\"DISABLED\" NAME=\"actiune\" id=\"button11_2\" VALUE=\"\">";
					echo "</TD>";
				}
				echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
				echo "&nbsp".$row["anulat"]."&nbsp";
				echo "</TD>";
				$i++;
			}
				
				echo "<TR>";
				echo "<TD>&nbsp</TD>";
				echo "</TR>";

				echo "<tr>";
			    echo "<td colspan=\"4\" align=\"right\">";
				echo "Total:";
				echo "</TD>";
			    echo "<td colspan=\"1\" align=\"center\">";
				echo $platit_tot;
				echo "</TD>";
				echo "</TR>";
				
				echo "<TR>";
				echo "<TD>&nbsp</TD>";
				echo "</TR>";
				
		echo "</form>";
		echo "</table>";	
		mysql_close($connection);
}


if ($_POST["actiune"]==="BORDEROU DEBITE SI PLATI")
{
			$wan2=$_POST["an"]+1;	
	
			echo "<CENTER>";
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<TR BGCOLOR=\"#4EAEF2\">";
			echo "<TD colspan=\"11\" class=\"style2\" height=\"25\" align=\"center\">";
			echo "<B> ".$_POST["den_aplic"]."</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "<TR BGCOLOR=\"#A3D9FF\">";
			echo "<TD width=\"250\" class=\"style2\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
			echo "</TD>";
			echo "<TD width=\"160\" class=\"style2\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
			echo "</TD>";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "</table>";
		
			echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
			echo "<tr>";
			echo "<td colspan=\"20\" height=\"1px\"></td>";
			echo "</tr>";
			echo "</table>";
			
			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
			
			//echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
			echo "<FORM NAME=\"form\" ACTION=\"A21_lista_bord_deb_plati.php\" METHOD=\"POST\" target=\"_blank\">";
			include 'A21_param1.php';
		
			$wdenluna_sel=substr($_POST["luna_sel"],3,strlen($_POST["luna_sel"])-3);
			$wdengrp_sel=substr($_POST["grp_sel"],3,strlen($_POST["grp_sel"])-3);
	
			echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>BORDEROU DE DEBITE SI PLATI</B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>GRUPA:&nbsp<U>".$wdengrp_sel."</U>&nbsp &nbsp &nbsp &nbsp &nbsp</B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";			
			echo "<TR>";
			echo "<TD align=\"center\" class=\"td_print2\">";
			echo "<B>LUNA:&nbsp<U>".$wdenluna_sel."</U>&nbsp&nbsp&nbsp ANUL SCOLAR:&nbsp<U>".$_POST["an"]." - ".$wan2."</U></B>";
			echo "<BR>";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";
			
			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"60%; height:100%;\" border=0 align=\"right\">";
			echo "<TR>";
			echo "<TD align=\"right\" height=\"35\">";
			//echo "<input type=\"button\" class=\"noPrint\" onClick=\"window.print()\" value=\"PRINTARE\">";
			echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"LISTARE\">";
			echo "</TD>";
			echo "</FORM>";
			echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
			include 'A21_param1.php';
			echo "<TD align=\"left\" height=\"35\">";
			echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"INAPOI\">";
			echo "</TD>";
			echo "</TR>";
			echo "</TABLE>";


			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"60%\" class=\"tabel_bord\" border=0>";
			echo "<BR>";
			echo "<TR BGCOLOR=\"white\">";
			
			echo 	"<TH align=\"center\" rowspan=\"2\" width=\"2%\" class=\"td35\">ID</TH>";					
			echo	"<TH align=\"center\" rowspan=\"2\" width=\"10%\"  class=\"td35\">Nume Prenume prescolar</TH>";		
			
			echo	"<TH align=\"center\" colspan=\"2\" scope=\"colgroup\" width=\"3%\" class=\"td39\">PRECEDENT</TH>";
			echo	"<TH align=\"center\" colspan=\"2\" scope=\"colgroup\" width=\"3%\" class=\"td35\">Luna &nbsp ".$wdenluna_sel."</TH>";	
			echo	"<TH align=\"center\" colspan=\"3\" scope=\"colgroup\" width=\"3%\" class=\"td39\">CUMULAT</TH>";
			echo 	"</TR>";
			echo    "<TR BGCOLOR=\"white\">";
			echo	"<TH align=\"center\" scope=\"row\" width=\"1%\" class=\"td35\">Debite</TH>";
			echo	"<TH align=\"center\" scope=\"row\" width=\"1%\" class=\"td35\">Plati</TH>";
			echo	"<TH align=\"center\" scope=\"row\" width=\"1%\" class=\"td35\">Debite</TH>";
			echo	"<TH align=\"center\" scope=\"row\" width=\"1%\" class=\"td35\">Plati</TH>";	
			echo	"<TH align=\"center\" scope=\"row\" width=\"1%\" class=\"td35\">Debite</TH>";
			echo	"<TH align=\"center\" scope=\"row\" width=\"1%\" class=\"td35\">Plati</TH>";
			echo	"<TH align=\"center\" scope=\"row\" width=\"1%\" class=\"td39\">Rest_PL</TH>";
			echo    "</TR>";
					
			$query="SELECT * FROM copii WHERE codgrp=\"".substr($_POST["grp_sel"],0,2)."\"  order by nume,prenume,codcopil";
			$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());

		$i=0;
		$wlu=substr($_POST["luna_sel"],0,2);	
		
		$wdebit=0;
		$wplati=0;
		$wrest=0;
		$wdebit_tot=0;
		$wplati_tot=0;
		$wrest_tot=0;
		$wdebit_prec=0;
		$wplati_prec=0;
		
		while($row=mysql_fetch_array($result))	
		{ 			
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
				echo "<TD width=\"2%\" align=\"center\">";
				echo "".$row["codcopil"]."";
				echo "</TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "&nbsp".trim($row["nume"])." ".trim($row["prenume"])."&nbsp";
				echo "</TD>";

				if($wlu==="01")
				{			
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val01"];
					$plati_prec=$plati_ln - $row["p_val01"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val01"];
					$wplati += $row["p_val01"];
					$wrest += $row["r_val01"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;					
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val01"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val01"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";									
				}
				if($wlu==="02")
				{
				
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val02"];
					$plati_prec=$plati_ln - $row["p_val02"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val02"];
					$wplati += $row["p_val02"];
					$wrest += $row["r_val02"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val02"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val02"]."&nbsp";
					echo "</TD>";				
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";					
				}
				if($wlu==="03")
				{				
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val03"];
					$plati_prec=$plati_ln - $row["p_val03"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val03"];
					$wplati += $row["p_val03"];
					$wrest += $row["r_val03"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";				
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val03"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val03"]."&nbsp";
					echo "</TD>";				
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";		
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";		
				}
				if($wlu==="04")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val04"];
					$plati_prec=$plati_ln - $row["p_val04"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val04"];
					$wplati += $row["p_val04"];
					$wrest += $row["r_val04"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val04"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val04"]."&nbsp";
					echo "</TD>";			
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";				
				}
				if($wlu==="05")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val05"];
					$plati_prec=$plati_ln - $row["p_val05"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val05"];
					$wplati += $row["p_val05"];
					$wrest += $row["r_val05"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val05"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val05"]."&nbsp";
					echo "</TD>";				
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";				
				}
				if($wlu==="06")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val06"];
					$plati_prec=$plati_ln - $row["p_val06"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val06"];
					$wplati += $row["p_val06"];
					$wrest += $row["r_val06"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val06"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val06"]."&nbsp";
					echo "</TD>";					
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";				
				}
				if($wlu==="07")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"]+$row["d_val07"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"]+$row["p_val07"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val07"];
					$plati_prec=$plati_ln - $row["p_val07"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val07"];
					$wplati += $row["p_val07"];
					$wrest += $row["r_val07"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val07"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val07"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";				
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";				
				}
				if($wlu==="08")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"]+$row["d_val07"]+$row["d_val08"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"]+$row["p_val07"]+$row["p_val08"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val08"];
					$plati_prec=$plati_ln - $row["p_val08"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val08"];
					$wplati += $row["p_val08"];
					$wrest += $row["r_val08"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val08"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val08"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";									
				}
				if($wlu==="09")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"];
					$plati_ln=$row["p_val09"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val09"];
					$plati_prec=$plati_ln - $row["p_val09"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val09"];
					$wplati += $row["p_val09"];
					$wrest += $row["r_val09"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val09"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val09"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";					
				}
				if($wlu==="10")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"];
					$plati_ln=$row["p_val09"]+$row["p_val10"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val10"];
					$plati_prec=$plati_ln - $row["p_val10"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit += $row["d_val10"];
					$wplati += $row["p_val10"];
					$wrest += $row["r_val10"];
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
				
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val10"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val10"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";				
				}
				if($wlu==="11")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val11"];
					$plati_prec=$plati_ln - $row["p_val11"];

					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}					
					
					$wdebit += $row["d_val11"];
					$wplati += $row["p_val11"];
					$wrest += $row["r_val11"];
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
					
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val11"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["p_val11"]."&nbsp";
					echo "</TD>";	
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";									
				}
				if($wlu==="12")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"];
					$plati_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"];
					$rest_ln= $debit_ln - $plati_ln;
					
					$debit_prec=$debit_ln - $row["d_val12"];
					$plati_prec=$plati_ln - $row["p_val12"];
					
					if ($debit_prec == 0)
					{
						$debit_prec = ' ';
					}
					if ($plati_prec == 0 )
					{
						$plati_prec = ' ';
					}
					
					$wdebit += $row["d_val12"];
					$wplati += $row["p_val12"];
					$wrest += $row["r_val12"];
					
					$wdebit_prec += $debit_prec;
					$wplati_prec += $plati_prec;
					
					$wdebit_tot += $debit_ln;
					$wplati_tot += $plati_ln;
					$wrest_tot += $rest_ln;
				
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$debit_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"2%\" align=\"right\">";
					echo "&nbsp".$plati_prec."&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";
					echo "&nbsp".$row["d_val12"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"2%\" align=\"right\">";
					echo "&nbsp".$row["p_val12"]."&nbsp";
					echo "</TD>";
					echo"<TD width=\"2%\" align=\"right\">";					
					echo "<B>".$debit_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"1%\" align=\"right\">";					
					echo "<B>".$plati_ln."</B>&nbsp";
					echo "</TD>";
					echo"<TD width=\"2%\" align=\"right\">";					
					echo "<B>".$rest_ln."</B>&nbsp";
					echo "</TD>";									
				}
				
				
				echo "</TR>";
				$i++;
		}		

			echo "<TR>";
			echo "<TD colspan=\"9\">&nbsp</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD colspan=\"9\"><HR></HR>&nbsp</TD>";
			echo "</TR>";			
			echo "<TR class=\"tr4\">";		
			echo "<TD width=\"2%\" align=\"center\">";
			echo "</TD>";
			echo"<TD width=\"10%\" align=\"right\">";
			echo "<B>TOTAL:</B>";
			echo "</TD>";
			echo"<TD width=\"1%\" align=\"right\">";
			echo "<B>&nbsp".$wdebit_prec."&nbsp</B>";
			echo "</TD>";
			echo"<TD width=\"1%\" align=\"right\">";
			echo "<B>&nbsp".$wplati_prec."&nbsp</B>";
			echo "</TD>";			
			echo"<TD width=\"1%\" align=\"right\">";
			echo "<B>&nbsp".$wdebit."&nbsp</B>";
			echo "</TD>";
			echo"<TD width=\"1%\" align=\"right\">";
			echo "<B>&nbsp".$wplati."&nbsp</B>";
			echo "</TD>";
			echo"<TD width=\"1%\" align=\"right\">";					
			echo "<B>".$wdebit_tot."</B>&nbsp";
			echo "</TD>";
			echo"<TD width=\"1%\" align=\"right\">";					
			echo "<B>".$wplati_tot."</B>&nbsp";
			echo "</TD>";
			echo"<TD width=\"1%\" align=\"right\">";					
			echo "<B>".$wrest_tot."</B>&nbsp";
			echo "</TD>";		
			echo "</table>";
/*		
			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"60%\" class=\"tabel_bord_1\" border=0 align=\"center\">";
			echo "<BR>";
			echo "<tr>";
			echo "<hr width=\"60%\" class=\"hr_bord\" align=\"center\">";			
			echo "</tr>";
			echo "<TR>";
			echo 	"<TD align=\"right\" width=\"2%\"></TD>";					
			echo	"<TD align=\"right\" class=\"td41\"></TD>";
			echo	"<TD align=\"right\" width=\"1%\" class=\"td_bord\"><B>TOTAL:</B></TD>";
			echo	"<TD align=\"right\" width=\"2%\"><B>$wdebit_prec</B></TD>";
			echo	"<TD align=\"right\" width=\"2%\"><B>$wplati_prec</B></TD>";	
			echo	"<TD align=\"right\" width=\"2%\"><B>$wdebit</B></TD>";
			echo	"<TD align=\"right\" width=\"2%\"><B>$wplati</B></TD>";		
			echo	"<TD align=\"right\" width=\"2%\"><B>$wdebit_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"2%\"><B>$wplati_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$wrest_tot</B></TD>";
			echo "</TR>";
*/
		echo "</form>";
		
		//include 'A21_denfunctii.php';
		
		echo "</table>";	
		echo "</div>";
		echo "</div>";
		mysql_close($connection);		
}

if ($_POST["actiune"]==="BORDEROU INCASARI")
{
		$wan2=$_POST["an"]+1;

		echo "<CENTER>";
		echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
		echo "<tr>";
		echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
		echo "</tr>";
		echo "<TR BGCOLOR=\"#4EAEF2\">";
		echo "<TD colspan=\"11\" class=\"style2\" height=\"25\" align=\"center\">";
		echo "<B> ".$_POST["den_aplic"]."</B>";
		echo "</TD>";
		echo "</TR>";
		echo "<tr>";
		echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
		echo "</tr>";
		echo "<TR BGCOLOR=\"#A3D9FF\">";
		echo "<TD width=\"250\" class=\"style2\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
		echo "</TD>";
		echo "<TD width=\"160\" class=\"style2\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
		echo "</TD>";
		echo "</td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
		echo "</tr>";
		echo "</table>";

		echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
		echo "<tr>";
		echo "<td colspan=\"20\" height=\"1px\"></td>";
		echo "</tr>";
		echo "</table>";
		
		$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
		$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
		$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
		
		echo "<FORM NAME=\"form\" ACTION=\"A21_lista_bord_incasari.php\" METHOD=\"POST\" target=\"_blank\">";
		include 'A21_param1.php';
		
		$wdenluna_sel=substr($_POST["luna_sel"],3,strlen($_POST["luna_sel"])-3);
		$wdengrp_sel=substr($_POST["grp_sel"],3,strlen($_POST["grp_sel"])-3);
		
		echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
		echo "<TR>";
		echo "<TD align=\"center\" class=\"td_print2\">";
		echo "<B>BORDEROU INCASARI</B>";
		echo "<BR>";
		echo "</TD>";
		echo "</TR>";				
//			echo "<TR>";
//			echo "<TD align=\"center\" class=\"td_print2\">";
//			echo "<B>GRUPA:&nbsp<U>".$wdengrp_sel."</U>&nbsp &nbsp &nbsp &nbsp &nbsp</B>";
//			echo "<BR>";
//			echo "</TD>";
//			echo "</TR>";			
		echo "<TR>";
		echo "<TD align=\"center\" class=\"td_print2\">";
		echo "<B>LUNA:&nbsp<U>".$wdenluna_sel."</U>&nbsp&nbsp&nbsp ANUL SCOLAR:&nbsp<U>".$_POST["an"]." - ".$wan2."</U></B>";
		echo "<BR>";
		echo "</TD>";
		echo "</TR>";
		echo "</TABLE>";
		
		echo "<TABLE cellSpacing=0 cellPadding=0 width=\"60%; height:100%;\" border=0 align=\"right\">";
		echo "<TR>";
		echo "<TD align=\"right\" height=\"35\">";
		//echo "<input type=\"button\" class=\"noPrint\" onClick=\"window.print()\" value=\"PRINTARE\">";
		echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"LISTARE\">";
		echo "</TD>";
		echo "</FORM>";
		echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
		include 'A21_param1.php';
		echo "<TD align=\"left\" height=\"35\">";
		echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"INAPOI\">";
		echo "</TD>";
		echo "</TR>";
		echo "</TABLE>";

		echo "<TABLE cellSpacing=0 cellPadding=0 class=\"table23\" border=0>";
		echo "<BR>";
		echo "<TR BGCOLOR=\"white\">";
		
		echo 	"<TH align=\"center\" width=\"2%\" class=\"td35\">Nr. crt.</TH>";
		echo 	"<TH align=\"center\" width=\"4%\" class=\"td35\">ID</TH>";					
		echo	"<TH align=\"center\" width=\"25%\"  class=\"td35\">Nume Prenume prescolar</TH>";
		echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">Tip doc</TH>";		
		echo	"<TH align=\"center\" width=\"8%\" class=\"td35\">Data</TH>";			
		echo	"<TH align=\"center\" width=\"4%\" class=\"td35\">Nr. chitanta</TH>";
		echo	"<TH align=\"center\" width=\"4%\" class=\"td35\">Suma</TH>";
		echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">Anulat</TH>";
		echo	"<TH align=\"center\" width=\"15%\" class=\"td39\">Grupa</TH>";
		echo    "</TR>";
		
		$query = "SELECT id, codcopil, tip_doc, serie_doc, nr_doc, ln, data_doc, val_doc, anulat FROM chitante WHERE ln = \"".substr($_POST["luna_sel"],0,2)."\" order by data_doc,tip_doc,nr_doc";
		$result = mysql_query($query) or die("Interogare esuata: ".mysql_error());
		
		$i=0;
		$wcodcopilp = ' ';
		//$wlu=substr($_POST["luna_sel"],0,2);
		$suma_tot=0;
		while($row = mysql_fetch_array( $result))	
		{ 
			$wcodcopil = $row["codcopil"];
	
			$query1 = "SELECT codgrp, codcopil, nume, prenume FROM copii WHERE codcopil=\"".$wcodcopil."\" LIMIT 1";
			$result1 = mysql_query($query1) or die("Interogare esuata: ".mysql_error());	
			$row1 = mysql_fetch_array($result1);	
			
			$query1_1="SELECT codgrp,dengrp from grupe WHERE codgrp=\"".$row1["codgrp"]."\"";
			$result1_1=mysql_query($query1_1) or die("Interogare esuata: ".mysql_error());
			$row1_1=mysql_fetch_array($result1_1);
			
			IF (strpos($row1_1['dengrp'],'-') == TRUE)
			{
				$den_grupa = substr($row1_1["dengrp"], 0, strpos($row1_1["dengrp"], '-'));			
			}
			ELSE
			{
				$den_grupa = $row1_1['dengrp'];
			}
			
			if ($row["anulat"] <> 'X')
			{
				$suma_tot += $row["val_doc"];
			}	
			
			$data_doc = date("d-m-Y", strtotime($row["data_doc"]));
				
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
			
			echo "<TD width=\"2%\" align=\"center\">",$i+1,"</TD>";
							
			echo "<TD width=\"4%\" align=\"center\">";
			echo $wcodcopil;
			echo "</TD>";

			echo"<TD width=\"25%\" align=\"left\">";
			echo "&nbsp".trim($row1["nume"])." ".trim($row1["prenume"])."&nbsp";
			echo "</TD>";	
		
			echo"<TD width=\"3%\" align=\"center\">";
			echo "&nbsp".$row["tip_doc"]."&nbsp";
			echo "</TD>";
			echo"<TD width=\"8%\" align=\"center\">";
			echo "&nbsp".$data_doc."&nbsp";
			echo "</TD>";
			
			if ($row["tip_doc"] === "CHA")
			{
				echo"<TD width=\"4%\" align=\"center\">";
				echo "&nbsp".$row["serie_doc"]."_".$row["nr_doc"]."&nbsp";
				echo "</TD>";
			}
			else
			{				
				echo"<TD width=\"4%\" align=\"center\">";
				echo "&nbsp".$row["nr_doc"]."&nbsp";
				echo "</TD>";
			}
			if ($row["anulat"] === 'X')
			{
				echo"<TD width=\"4%\" align=\"center\">";
				echo "0&nbsp(".$row["val_doc"].")&nbsp";
				echo "</TD>";
			}
			else
			{				
				echo"<TD width=\"4%\" align=\"center\">";
				echo "&nbsp".$row["val_doc"]."&nbsp";
				echo "</TD>";
			}	
			echo"<TD width=\"3%\" align=\"center\">";
			echo "&nbsp".$row["anulat"]."&nbsp";
			echo "</TD>";
			echo"<TD width=\"15%\" align=\"left\">";
			echo "&nbsp".$den_grupa."&nbsp";
			echo "</TD>";			
			echo "</TR>";
			++$i;			
		}
		
			echo "<TR>";
			echo "<TD colspan=\"9\">&nbsp</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD colspan=\"9\"><HR></HR>&nbsp</TD>";
			echo "</TR>";	
			echo "<TR>";	
			echo "<TD width=\"2%\" align=\"center\">&nbsp</TD>";				
			echo "<TD width=\"4%\" align=\"center\">&nbsp</TD>";
			echo"<TD width=\"15%\" align=\"left\">&nbsp</TD>";
			echo"<TD width=\"3%\" align=\"center\">&nbsp</TD>";
			echo"<TD width=\"8%\" align=\"center\">&nbsp</TD>";
			echo"<TD width=\"4%\" align=\"center\"><B>TOTAL:</B></TD>";
			echo"<TD width=\"4%\" align=\"center\"><B>$suma_tot</B></TD>";	
			echo"<TD width=\"3%\" align=\"center\">&nbsp</TD>";
			echo "</TR>";
/*
			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"60%\" border=0 align=\"center\">";
			echo "<BR>";
			echo "<tr>";
			echo "<hr class=\"hr3\" align=\"center\">";			
			echo "</tr>";
			echo "<TR>";		
			echo	"<TD align=\"right\" class=\"td_tot\"><B>TOTAL:</B></TD>";	
			echo	"<TD align=\"center\" class=\"td_sum\"><B>$suma_tot</B></TD>";
			echo "</TR>";
			echo "</TABLE>";
*/			
			//include 'A21_denfunctii.php';
			
			
	mysql_close($connection);
		
}
if ($_POST["actiune"]==="RECAPITULATIE")
{
	$wan2=$_POST["an"]+1;

	echo "<CENTER>";
	echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "<TR BGCOLOR=\"#4EAEF2\">";
	echo "<TD colspan=\"11\" class=\"style2\" height=\"25\" align=\"center\">";
	echo "<B> ".$_POST["den_aplic"]."</B>";
	echo "</TD>";
	echo "</TR>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "<TR BGCOLOR=\"#A3D9FF\">";
	echo "<TD width=\"250\" class=\"style2\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
	echo "</TD>";
	echo "<TD width=\"160\" class=\"style2\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
	echo "</TD>";
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "</table>";

	echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	echo "<tr>";
	echo "<td colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "</table>";
	
	$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
	$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
	$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
	
	echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
	include 'A21_param1.php';
	
	$wdenluna_sel=substr($_POST["luna_sel"],3,strlen($_POST["luna_sel"])-3);
	$wdengrp_sel=substr($_POST["grp_sel"],3,strlen($_POST["grp_sel"])-3);
	
	echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
	echo "<TR>";
	echo "<TD align=\"center\" class=\"td_print2\">";
	echo "<B>RECAPITULATIE</B>";
	echo "<BR>";
	echo "</TD>";
	echo "</TR>";

	echo "<TR>";
	echo "<TD align=\"center\" class=\"td_print2\">";
	echo "<B>LUNA:&nbsp<U>".$wdenluna_sel."</U>&nbsp&nbsp&nbsp&nbsp ANUL SCOLAR:&nbsp<U>".$_POST["an"]." - ".$wan2."</U></B>";
	echo "<BR>";
	echo "</TD>";
	echo "</TR>";
	echo "</TABLE>";
	
	echo "<TABLE cellSpacing=0 cellPadding=0 width=\"100%;\" border=0 align=\"center\">";
	echo "<TR>";
	echo "<TD align=\"right\" height=\"35\">";
	echo "<input type=\"button\" class=\"noPrint\" onClick=\"window.print()\" value=\"PRINTARE\">";
	echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"INAPOI\">";
	echo "</TD>";
	echo "</TR>";
	echo "</TABLE>";

	echo "<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	echo "<BR>";
	echo "<TR BGCOLOR=\"white\">";
	
	echo 	"<TH align=\"center\" width=\"2%\" class=\"td35\">Nr. crt.</TH>";					
	echo	"<TH align=\"center\" width=\"10%\" class=\"td35\">Grupa</TH>";	
	echo	"<TH align=\"center\" width=\"1%\" class=\"td35\">Tip Reg</TH>";		
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">PREC</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">SEP</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">OCT</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">NOI</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">DEC</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IAN</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">FEB</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAR</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">APR</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">MAI</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUN</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">IUL</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">AUG</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td39\">TOTAL</TH>";
	
	echo "</TR>";
	
	$query="SELECT id,codgrp,codcopil,nume,prenume,sum(d_val00) as d_val00, sum(d_val01) as d_val01, sum(d_val02) as d_val02, sum(d_val03) as d_val03, sum(d_val04) as d_val04, sum(d_val05) as d_val05, sum(d_val06) as d_val06, sum(d_val07) as d_val07, sum(d_val08) as d_val08, sum(d_val09) as d_val09, sum(d_val10) as d_val10, sum(d_val11) as d_val11, sum(d_val12) as d_val12, sum(p_val01) as p_val01, sum(p_val02) as p_val02, sum(p_val03) as p_val03, sum(p_val04) as p_val04, sum(p_val05) as p_val05, sum(p_val06) as p_val06, sum(p_val07) as p_val07, sum(p_val08) as p_val08, sum(p_val09) as p_val09, sum(p_val10) as p_val10, sum(p_val11) as p_val11, sum(p_val12) as p_val12, sum(r_val01) as r_val01, sum(r_val02) as r_val02, sum(r_val03) as r_val03, sum(r_val04) as r_val04, sum(r_val05) as r_val05, sum(r_val06) as r_val06, sum(r_val07) as r_val07, sum(r_val08) as r_val08, sum(r_val09) as r_val09, sum(r_val10) as r_val10, sum(r_val11) as r_val11, sum(r_val12) as r_val12 FROM copii group by codgrp"	;	
	$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());

		$i=0;
		$wnrc=1;
		$debit_tot=0;
		$wlu=substr($_POST["luna_sel"],0,2);
		
		$d_val00_tot=0;
		$d_val01_tot=0;
		$d_val02_tot=0;
		$d_val03_tot=0;
		$d_val04_tot=0;
		$d_val05_tot=0;
		$d_val06_tot=0;
		$d_val07_tot=0;
		$d_val08_tot=0;
		$d_val09_tot=0;
		$d_val10_tot=0;
		$d_val11_tot=0;
		$d_val12_tot=0;
		$d_val_tot=0;
		$p_val01_tot=0;
		$p_val02_tot=0;
		$p_val03_tot=0;
		$p_val04_tot=0;
		$p_val05_tot=0;
		$p_val06_tot=0;
		$p_val07_tot=0;
		$p_val08_tot=0;
		$p_val09_tot=0;
		$p_val10_tot=0;
		$p_val11_tot=0;
		$p_val12_tot=0;
		$p_val_tot=0;
		$r_val01_tot=0;
		$r_val02_tot=0;
		$r_val03_tot=0;
		$r_val04_tot=0;
		$r_val05_tot=0;
		$r_val06_tot=0;
		$r_val07_tot=0;
		$r_val08_tot=0;
		$r_val09_tot=0;
		$r_val10_tot=0;
		$r_val11_tot=0;
		$r_val12_tot=0;
		$r_val_tot=0;
		
		while($row = mysql_fetch_array( $result))		
		{ 	
			$debit_tot = $row["d_val00"] + $row["d_val01"] + $row["d_val02"] + $row["d_val03"] + $row["d_val04"] + $row["d_val05"] + $row["d_val06"] + $row["d_val07"] + $row["d_val08"] + $row["d_val09"] + $row["d_val10"] + $row["d_val11"] + $row["d_val12"];
			$platit_tot = $row["p_val01"] + $row["p_val02"] + $row["p_val03"] + $row["p_val04"] + $row["p_val05"] + $row["p_val06"] + $row["p_val07"] + $row["p_val08"] + $row["p_val09"] + $row["p_val10"] + $row["p_val11"] + $row["p_val12"];
			$rest_tot = $debit_tot - $platit_tot;
			
			$d_val00_tot += $row["d_val00"];
			$d_val01_tot += $row["d_val01"];
			$d_val02_tot += $row["d_val02"];
			$d_val03_tot += $row["d_val03"];
			$d_val04_tot += $row["d_val04"];
			$d_val05_tot += $row["d_val05"];
			$d_val06_tot += $row["d_val06"];
			$d_val07_tot += $row["d_val07"];
			$d_val08_tot += $row["d_val08"];
			$d_val09_tot += $row["d_val09"];
			$d_val10_tot += $row["d_val10"];
			$d_val11_tot += $row["d_val11"];
			$d_val12_tot += $row["d_val12"];
			$d_val_tot = $d_val00_tot + $d_val01_tot + $d_val02_tot + $d_val03_tot + $d_val04_tot + $d_val05_tot + $d_val06_tot + $d_val07_tot + $d_val08_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot;
			
			$d_val01_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot + $d_val01_tot;
			$d_val02_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot + $d_val01_tot + $d_val02_tot;
			$d_val03_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot + $d_val01_tot + $d_val02_tot + $d_val03_tot;
			$d_val04_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot + $d_val01_tot + $d_val02_tot + $d_val03_tot + $d_val04_tot;			
			$d_val05_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot + $d_val01_tot + $d_val02_tot + $d_val03_tot + $d_val04_tot + $d_val05_tot;
			$d_val06_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot + $d_val01_tot + $d_val02_tot + $d_val03_tot + $d_val04_tot + $d_val05_tot + $d_val06_tot;
			$d_val07_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot + $d_val01_tot + $d_val02_tot + $d_val03_tot + $d_val04_tot + $d_val05_tot + $d_val06_tot + $d_val07_tot;
			$d_val08_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot + $d_val01_tot + $d_val02_tot + $d_val03_tot + $d_val04_tot + $d_val05_tot + $d_val06_tot + $d_val07_tot + $d_val08_tot;
			$d_val09_total = $d_val00_tot + $d_val09_tot;
			$d_val10_total = $d_val00_tot + $d_val09_tot + $d_val10_tot;
			$d_val11_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot;
			$d_val12_total = $d_val00_tot + $d_val09_tot + $d_val10_tot + $d_val11_tot + $d_val12_tot;

			$p_val01_tot += $row["p_val01"];
			$p_val02_tot += $row["p_val02"];
			$p_val03_tot += $row["p_val03"];
			$p_val04_tot += $row["p_val04"];
			$p_val05_tot += $row["p_val05"];
			$p_val06_tot += $row["p_val06"];
			$p_val07_tot += $row["p_val07"];
			$p_val08_tot += $row["p_val08"];
			$p_val09_tot += $row["p_val09"];
			$p_val10_tot += $row["p_val10"];
			$p_val11_tot += $row["p_val11"];
			$p_val12_tot += $row["p_val12"];
			$p_val_tot = $p_val01_tot + $p_val02_tot + $p_val03_tot + $p_val04_tot + $p_val05_tot + $p_val06_tot + $p_val07_tot + $p_val08_tot + $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot;
			
			$p_val01_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot + $p_val01_tot;
			$p_val02_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot + $p_val01_tot + $p_val02_tot;
			$p_val03_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot + $p_val01_tot + $p_val02_tot + $p_val03_tot;
			$p_val04_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot + $p_val01_tot + $p_val02_tot + $p_val03_tot + $p_val04_tot;
			$p_val05_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot + $p_val01_tot + $p_val02_tot + $p_val03_tot + $p_val04_tot + $p_val05_tot;
			$p_val06_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot + $p_val01_tot + $p_val02_tot + $p_val03_tot + $p_val04_tot + $p_val05_tot + $p_val06_tot;
			$p_val07_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot + $p_val01_tot + $p_val02_tot + $p_val03_tot + $p_val04_tot + $p_val05_tot + $p_val06_tot + $p_val07_tot;
			$p_val08_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot + $p_val01_tot + $p_val02_tot + $p_val03_tot + $p_val04_tot + $p_val05_tot + $p_val06_tot + $p_val07_tot + $p_val08_tot;
			$p_val09_total = $p_val09_tot;
			$p_val10_total = $p_val09_tot + $p_val10_tot;
			$p_val11_total = $p_val09_tot + $p_val10_tot + $p_val11_tot;
			$p_val12_total = $p_val09_tot + $p_val10_tot + $p_val11_tot + $p_val12_tot;
			
			$r_val01_tot += $row["r_val01"];
			$r_val02_tot += $row["r_val02"];
			$r_val03_tot += $row["r_val03"];
			$r_val04_tot += $row["r_val04"];
			$r_val05_tot += $row["r_val05"];
			$r_val06_tot += $row["r_val06"];
			$r_val07_tot += $row["r_val07"];
			$r_val08_tot += $row["r_val08"];
			$r_val09_tot += $row["r_val09"];
			$r_val10_tot += $row["r_val10"];
			$r_val11_tot += $row["r_val11"];
			$r_val12_tot += $row["r_val12"];
			
			IF ($row["codgrp"] <> 99)
			{
				$r_val_tot = $d_val_tot - $p_val_tot;
			}	
			
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
		
				echo "<TD width=\"2%\" align=\"center\">",$wnrc++,"</TD>";
				
				$query2 = "SELECT * from grupe where codgrp=\"".$row["codgrp"]."\" order by codgrp";
				$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());
				$row2 = mysql_fetch_array( $result2);
				
				echo"<TD width=\"10%\" align=\"left\">";
				echo "&nbsp".$row2["dengrp"]."&nbsp";
				echo "</TD>";
				echo"<TD width=\"1%\" align=\"center\">";
				echo "<B>DEBIT</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val00"]."&nbsp";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val09"]."&nbsp";
				if($wlu==="09")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val10"]."&nbsp";
				if($wlu==="10")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val11"]."&nbsp";
				if($wlu==="11")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val12"]."&nbsp";
				if($wlu==="12")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val01"]."&nbsp";
				if($wlu==="01")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val02"]."&nbsp";
				if($wlu==="02")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val03"]."&nbsp";
				if($wlu==="03")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val04"]."&nbsp";
				if($wlu==="04")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val05"]."&nbsp";
				if($wlu==="05")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val06"]."&nbsp";
				if($wlu==="06")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val07"]."&nbsp";
				if($wlu==="07")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"]+$row["d_val07"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["d_val08"]."&nbsp";
				if($wlu==="08")
				{
					$debit_ln=$row["d_val00"]+$row["d_val09"]+$row["d_val10"]+$row["d_val11"]+$row["d_val12"]+$row["d_val01"]+$row["d_val02"]+$row["d_val03"]+$row["d_val04"]+$row["d_val05"]+$row["d_val06"]+$row["d_val07"]+$row["d_val08"];
					echo "(<B>".$debit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $debit_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				$i++;
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
		
				//echo "<TD width=\"2%\" align=\"center\">",$i+1,"</TD>";
				echo "<TD width=\"2%\" align=\"center\"></TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "</TD>";
				echo"<TD width=\"1%\" align=\"center\">";
				echo "<B>PLATI</B>";
				echo "</TD>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo " ";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val09"]."&nbsp";
				if($wlu==="09")
				{
					$platit_ln=$row["p_val09"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val10"]."&nbsp";
				if($wlu==="10")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val11"]."&nbsp";
				if($wlu==="11")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val12"]."&nbsp";
				if($wlu==="12")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val01"]."&nbsp";
				if($wlu==="01")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val02"]."&nbsp";
				if($wlu==="02")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val03"]."&nbsp";
				if($wlu==="03")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val04"]."&nbsp";
				if($wlu==="04")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val05"]."&nbsp";
				if($wlu==="05")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val06"]."&nbsp";
				if($wlu==="06")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val07"]."&nbsp";
				if($wlu==="07")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"]+$row["p_val07"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "&nbsp".$row["p_val08"]."&nbsp";
				if($wlu==="08")
				{
					$platit_ln=$row["p_val09"]+$row["p_val10"]+$row["p_val11"]+$row["p_val12"]+$row["p_val01"]+$row["p_val02"]+$row["p_val03"]+$row["p_val04"]+$row["p_val05"]+$row["p_val06"]+$row["p_val07"]+$row["p_val08"];
					echo "(<B>".$platit_ln."</B>)&nbsp";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $platit_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				$i++;
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
		
				//echo "<TD width=\"2%\" align=\"center\">",$i+1,"</TD>";
				echo "<TD width=\"2%\" align=\"center\"></TD>";
				echo"<TD width=\"10%\" align=\"left\">";
				echo "</TD>";
				echo"<TD width=\"1%\" align=\"center\">";
				echo "<B>REST_PL</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo " ";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="09")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val09"]."&nbsp";
				if($wlu==="09")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="10")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val10"]."&nbsp";
				if($wlu==="10")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="11")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val11"]."&nbsp";
				if($wlu==="11")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="12")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val12"]."&nbsp";
				if($wlu==="12")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="01")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val01"]."&nbsp";
				if($wlu==="01")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="02")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val02"]."&nbsp";
				if($wlu==="02")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="03")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val03"]."&nbsp";
				if($wlu==="03")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="04")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val04"]."&nbsp";
				if($wlu==="04")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="05")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val05"]."&nbsp";
				if($wlu==="05")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="06")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val06"]."&nbsp";
				if($wlu==="06")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="07")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val07"]."&nbsp";
				if($wlu==="07")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\" style=\"font-weight:bold;\">";
				if($wlu==="08")
				{
					echo "<B>";
				}
				echo "&nbsp".$row["r_val08"]."&nbsp";
				if($wlu==="08")
				{
					echo "</B>";
				}
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				
				IF ($row["codgrp"] == 99)
				{
					$rest_tot = 0;
				}			
				
				echo "<B>&nbsp $rest_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				
				echo "<TR>";
				echo "<TD>";
				echo "<BR>";
				echo "</TD>";
				echo "</TR>";
				$i++;
		}
					
				echo "<TR>";
				echo "<TD colspan=\"17\">&nbsp</TD>";
				echo "</TR>";
				echo "<TR>";
				echo "<TD colspan=\"17\"><HR></HR>&nbsp</TD>";
				echo "</TR>";	
				echo "<TR class=\"tr4\">";
				echo "<TD width=\"2%\" align=\"center\">&nbsp</TD>";
				echo"<TD width=\"10%\" align=\"right\"><B>TOTAL:</B></TD>";
				echo"<TD width=\"1%\" align=\"center\">";
				echo "<B>DEBIT</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\"><B>$d_val00_tot</B></TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="09")
				{
				echo	"<B>$d_val09_tot ($d_val09_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val09_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="10")
				{
				echo	"<B>$d_val10_tot ($d_val10_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val10_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="11")
				{
				echo	"<B>$d_val11_tot ($d_val11_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val11_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="12")
				{
				echo	"<B>$d_val12_tot ($d_val12_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val12_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="01")
				{
				echo	"<B>$d_val01_tot ($d_val01_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val01_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="02")
				{
				echo	"<B>$d_val02_tot ($d_val02_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val02_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="03")
				{
				echo	"<B>$d_val03_tot ($d_val03_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val03_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="04")
				{
				echo	"<B>$d_val04_tot ($d_val04_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val04_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="05")
				{
				echo	"<B>$d_val05_tot ($d_val05_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val05_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="06")
				{
				echo	"<B>$d_val06_tot ($d_val06_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val06_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="07")
				{
				echo	"<B>$d_val07_tot ($d_val07_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val07_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="08")
				{
				echo	"<B>$d_val08_tot ($d_val08_total)</B>";				
				}
				else
				{
				echo	"<B>$d_val08_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $d_val_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";	
				echo "<TR class=\"tr4\">";
				echo "<TD width=\"2%\" align=\"center\">&nbsp</TD>";
				echo"<TD width=\"10%\" align=\"left\">&nbsp</TD>";
				echo"<TD width=\"1%\" align=\"center\">";
				echo "<B>PLATI</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="09")
				{
				echo	"<B>$p_val09_tot ($p_val09_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val09_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="10")
				{
				echo	"<B>$p_val10_tot ($p_val10_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val10_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="11")
				{
				echo	"<B>$p_val11_tot ($p_val11_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val11_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="12")
				{
				echo	"<B>$p_val12_tot ($p_val12_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val12_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="01")
				{
				echo	"<B>$p_val01_tot ($p_val01_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val01_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="02")
				{
				echo	"<B>$p_val02_tot ($p_val02_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val02_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="03")
				{
				echo	"<B>$p_val03_tot ($p_val03_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val03_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="04")
				{
				echo	"<B>$p_val04_tot ($p_val04_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val04_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="05")
				{
				echo	"<B>$p_val05_tot ($p_val05_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val05_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="06")
				{
				echo	"<B>$p_val06_tot ($p_val06_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val06_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="07")
				{
				echo	"<B>$p_val07_tot ($p_val07_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val07_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				if($wlu==="08")
				{
				echo	"<B>$p_val08_tot ($p_val08_total)</B>";				
				}
				else
				{
				echo	"<B>$p_val08_tot</B>";
				}	
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $p_val_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";
				echo "<TR class=\"tr4\">";
				echo "<TD width=\"2%\" align=\"center\">&nbsp</TD>";
				echo"<TD width=\"10%\" align=\"left\">&nbsp</TD>";
				echo"<TD width=\"1%\" align=\"center\">";
				echo "<B>REST_PL</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val09_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val10_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val11_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val12_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val01_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";				
				echo	"<B>$r_val02_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val03_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val04_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val05_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val06_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val07_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">&nbsp";
				echo	"<B>$r_val08_tot</B>";
				echo "</TD>";
				echo"<TD width=\"3%\" align=\"right\">";
				echo "<B>&nbsp $r_val_tot &nbsp</B>";
				echo "</TD>";
				echo "</TR>";	
/*				
			echo "<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
			echo "<tr>";
			echo "<hr width=\"100%\" align=\"center\">";			
			echo "</tr>";
			echo "<TR>";			
	//		echo 	"<TD align=\"right\" width=\"1%\"></TD>";					
			echo	"<TD align=\"right\" width=\"12%\" class=\"td_recap\"><B>TOTAL:</B></TD>";	
			echo	"<TD align=\"center\" width=\"1%\"><B>DEBIT</B></TD>";		
			echo	"<TD align=\"right\" width=\"1%\"><B>$d_val00_tot</B></TD>";
			if($wlu=="01")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val01_tot ($d_val01_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val01_tot</B></TD>";
			}	
			if($wlu=="02")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val02_tot ($d_val02_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val02_tot</B></TD>";
			}
			if($wlu=="03")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val03_tot ($d_val03_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val03_tot</B></TD>";
			}
			if($wlu=="04")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val04_tot ($d_val04_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val04_tot</B></TD>";
			}
			if($wlu=="05")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val05_tot ($d_val05_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val05_tot</B></TD>";
			}
			if($wlu=="06")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val06_tot ($d_val06_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val06_tot</B></TD>";
			}
			if($wlu=="07")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val07_tot ($d_val07_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val07_tot</B></TD>";
			}
			if($wlu=="08")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val08_tot ($d_val08_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val08_tot</B></TD>";
			}
			if($wlu=="09")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val09_tot ($d_val09_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val09_tot</B></TD>";
			}
			if($wlu=="10")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val10_tot ($d_val10_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val10_tot</B></TD>";
			}
			if($wlu=="11")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val11_tot ($d_val11_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val11_tot</B></TD>";
			}
			if($wlu=="12")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$d_val12_tot ($d_val12_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val12_tot</B></TD>";
			}
			echo	"<TD align=\"right\" width=\"3%\"><B>$d_val_tot</B></TD>";
			echo "</TR>";
			echo "<TR>";			
//			echo 	"<TD align=\"right\" width=\"2%\"></TD>";					
			echo	"<TD align=\"right\" width=\"12%\" class=\"td_recap\"></TD>";	
			echo	"<TD align=\"center\" width=\"1%\"><B>PLATI</B></TD>";		
			echo	"<TD align=\"right\" width=\"2%\"></TD>";
			if($wlu=="01")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val01_tot ($p_val01_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val01_tot</B></TD>";
			}
			if($wlu=="02")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val02_tot ($p_val02_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val02_tot</B></TD>";
			}
			if($wlu=="03")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val03_tot ($p_val03_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val03_tot</B></TD>";
			}
			if($wlu=="04")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val04_tot ($p_val04_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val04_tot</B></TD>";
			}
			if($wlu=="05")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val05_tot ($p_val05_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val05_tot</B></TD>";
			}
			if($wlu=="06")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val06_tot ($p_val06_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val06_tot</B></TD>";
			}
			if($wlu=="07")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val07_tot ($p_val07_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val07_tot</B></TD>";
			}
			if($wlu=="08")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val08_tot ($p_val08_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val08_tot</B></TD>";
			}
			if($wlu=="09")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val09_tot ($p_val09_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val09_tot</B></TD>";
			}
			if($wlu=="10")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val10_tot ($p_val10_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val10_tot</B></TD>";
			}
			if($wlu=="11")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val11_tot ($p_val11_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val11_tot</B></TD>";
			}
			if($wlu=="12")
			{
			 echo	"<TD align=\"right\" width=\"4%\"><B>$p_val12_tot ($p_val12_total)</B></TD>";				
			}
			else
			{
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val12_tot</B></TD>";
			}
			echo	"<TD align=\"right\" width=\"3%\"><B>$p_val_tot</B></TD>";
			echo "</TR>";	
			echo "<TR>";			
	//		echo 	"<TD align=\"right\" width=\"2%\"></TD>";					
			echo	"<TD align=\"right\" width=\"12%\" class=\"td_recap\"></TD>";	
			echo	"<TD align=\"center\" width=\"1%\"><B>REST_PL</B></TD>";		
			echo	"<TD align=\"right\" width=\"3%\"></TD>";				
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val01_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val02_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val03_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val04_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val05_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val06_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val07_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val08_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val09_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val10_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val11_tot</B></TD>";
			echo	"<TD align=\"right\" width=\"3%\"><B>$r_val12_tot</B></TD>";			
			echo	"<TD align=\"right\" width=\"3.5%\"><B>$r_val_tot</B></TD>";
			echo "</TR>";	
			echo "</TABLE>";
	*/		
		include 'A21_denfunctii.php';

		echo "</form>";
		echo "</table>";	
 
		mysql_close($connection);
		echo "</center>";
}
if ($_POST["actiune"]==="REZUMAT INCASARI")
{
		$wan2=$_POST["an"]+1;

		echo "<CENTER>";
		echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
		echo "<tr>";
		echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
		echo "</tr>";
		echo "<TR BGCOLOR=\"#4EAEF2\">";
		echo "<TD colspan=\"11\" class=\"style2\" height=\"25\" align=\"center\">";
		echo "<B> ".$_POST["den_aplic"]."</B>";
		echo "</TD>";
		echo "</TR>";
		echo "<tr>";
		echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
		echo "</tr>";
		echo "<TR BGCOLOR=\"#A3D9FF\">";
		echo "<TD width=\"250\" class=\"style2\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
		echo "</TD>";
		echo "<TD width=\"160\" class=\"style2\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
		echo "</TD>";
		echo "</td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
		echo "</tr>";
		echo "</table>";

		echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
		echo "<tr>";
		echo "<td colspan=\"20\" height=\"1px\"></td>";
		echo "</tr>";
		echo "</table>";
		
		$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
		$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
		$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
		
		echo "<FORM NAME=\"form\" ACTION=\"A21_lista_reg_luna.php\" METHOD=\"POST\" target=\"_blank\">";
		include 'A21_param1.php';
		
		$wdenluna_sel=substr($_POST["luna_sel"],3,strlen($_POST["luna_sel"])-3);
		$wdengrp_sel=substr($_POST["grp_sel"],3,strlen($_POST["grp_sel"])-3);
		
		echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
		echo "<TR>";
		echo "<TD align=\"center\" class=\"td_print2\">";
		echo "<B>REZUMAT INCASARI</B>";
		echo "<BR>";
		echo "</TD>";
		echo "</TR>";				
/* 		echo "<TR>";
		echo "<TD align=\"center\" class=\"td_print2\">";
		echo "<B><U>".$wdengrp_sel."</U>&nbsp &nbsp &nbsp &nbsp &nbsp</B>";
		echo "<BR>";
		echo "</TD>";
		echo "</TR>";	 */		
		echo "<TR>";
		echo "<TD align=\"center\" class=\"td_print2\">";
		echo "<B>LUNA:&nbsp<U>".$wdenluna_sel."</U>&nbsp&nbsp&nbsp ANUL SCOLAR:&nbsp<U>".$_POST["an"]." - ".$wan2."</U></B>";
		echo "<BR>";
		echo "</TD>";
		echo "</TR>";
		echo "</TABLE>";
		echo "<TABLE cellSpacing=0 cellPadding=0 border=0 width=\"100%\" style=\"align:center;\">";		
		echo "<tr><td><BR></td></tr>";
		echo "</TABLE>";			
		
		echo "<TABLE cellSpacing=0 cellPadding=0 width=\"76%; height:100%;\" border=0 align=\"right\">";
		echo "<TR>";
		echo "<TD align=\"right\" height=\"35\">";
		echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"LISTARE\">";
		echo "</TD>";
		echo "</FORM>";
		
		echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
		include 'A21_param1.php';
		echo "<TD align=\"left\" height=\"35\">";
		echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"INAPOI\">";
		echo "</TD>";
		echo "</TR>";
		echo "</TABLE>";
			
		$query00="DELETE FROM reg_man";
		$result00=mysql_query($query00) or die("Interogare esuata: ".mysql_error());		
		
		$query01 = "SELECT ln, data_doc, val_doc, anulat FROM chitante WHERE ln = \"".substr($_POST["luna_sel"],0,2)."\" AND anulat IS NULL GROUP BY data_doc order by data_doc,id";
		$result01 = mysql_query($query01) or die("Interogare esuata: ".mysql_error());	
	
		while($row01 = mysql_fetch_array( $result01))	
		{ 	
			$suma_tot_zi=0;	
			$nr_ch = 0;
			$nr_ch_a = 0;
			//$query02 = "SELECT data_doc, val_doc, anulat FROM chitante WHERE data_doc = \"".$row01['data_doc']."\" AND anulat IS NULL order by id";
			$query02 = "SELECT data_doc, val_doc, anulat FROM chitante WHERE data_doc = \"".$row01['data_doc']."\" order by id";
			$result02 = mysql_query($query02) or die("Interogare esuata: ".mysql_error());		
			while($row02 = mysql_fetch_array( $result02))	
			{ 	
				IF ($row02['anulat'] == 'X')
				{
					++$nr_ch_a;
				}	
				ELSE
				{								
					$suma_tot_zi = $suma_tot_zi + $row02['val_doc'];
				}
				
				++$nr_ch;
			}
			
			$wziua=date('d-m-Y',strtotime($row01["data_doc"]));
				
			$query03="INSERT INTO reg_man (ziua,val,nr_ch,nr_ch_a) VALUES (\"".$wziua."\",\"".$suma_tot_zi."\",\"".$nr_ch."\",\"".$nr_ch_a."\")";
			$result03=mysql_query($query03) or die("Interogare esuata: ".mysql_error());				
		}
		
		echo "<TABLE cellSpacing=0 cellPadding=0 border=0 width=\"100%\" style=\"align:center;\">";		
		echo "<tr><td><BR></td></tr>";
		echo "</TABLE>";	
		echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 border=1 width=\"40%\" style=\"align:center;font-size:12pt;\">";
		echo "<TR BGCOLOR=\"white\" align=\"center\">";
		
		echo 	"<TH align=\"center\" colspan=\"1\" width=\"10%\">Nr. crt.</TH>";
		echo 	"<TH align=\"center\" colspan=\"1\" width=\"15%\">Data</TH>";					
		echo 	"<TH align=\"center\" colspan=\"1\" width=\"10%\">Nr. CH</TH>";					
		echo 	"<TH align=\"center\" colspan=\"1\" width=\"10%\">Din care anulate</TH>";					
		echo	"<TH align=\"center\" colspan=\"1\" width=\"15%\">Suma</TH>";
		echo    "</TR>";
		
		$query = "SELECT * FROM reg_man order by id";
		$result = mysql_query($query) or die("Interogare esuata: ".mysql_error());
		
		$i=1;
		$suma_tot_luna=0;
		while($row = mysql_fetch_array( $result))	
		{ 
			$suma_tot_luna += $row["val"];
	
			if ($i-floor($i/2)*2==0)
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
			}
			else
			{
				echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
			}
			
			echo "<TD width=\"10%\" colspan=\"1\" align=\"center\">",$i,"</TD>";							
			echo "<TD width=\"15%\" colspan=\"1\" align=\"center\">".$row['ziua']."</TD>";
			echo "<TD width=\"15%\" colspan=\"1\" align=\"center\">".$row['nr_ch']."</TD>";
			echo "<TD width=\"15%\" colspan=\"1\" align=\"center\">".$row['nr_ch_a']."</TD>";
			echo"<TD width=\"15%\" colspan=\"1\" align=\"center\">".$row['val']."</TD>";
			echo "</TR>";
			++$i;			
		}
		echo "</TABLE>";		
		
		echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 border=0 width=\"40%\" style=\"align:center;font-size:11pt;\">";		
		echo "<TR>";
		echo "<TD colspan=\"3\"><HR></HR></TD>";
		echo "</TR>";	
		echo "<TR>";
		echo"<TD width=\"20%\" align=\"center\"></TD>";			
		echo"<TD width=\"20%\" align=\"center\"></TD>";			
		echo"<TD width=\"20%\" align=\"center\"><B>TOTAL: $suma_tot_luna</B></TD>";	
		echo "</TR>";
	
	mysql_close($connection);
		
}
if ($_POST["actiune"]==="CONFIRM" AND isset($_POST["tip_act"]) AND $_POST["tip_act"]==="REGISTRU DE CASA")
{
	$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
	$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];
	$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);		
	
	$wan2=$_POST["an"]+1;

	echo "<CENTER>";
	echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "<TR BGCOLOR=\"#4EAEF2\">";
	echo "<TD colspan=\"11\" class=\"style2\" height=\"25\" align=\"center\">";
	echo "<B> ".$_POST["den_aplic"]."</B>";
	echo "</TD>";
	echo "</TR>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "<TR BGCOLOR=\"#A3D9FF\">";
	echo "<TD width=\"250\" class=\"style2\" colspan=\"2\" height=\"25\" align=\"left\"><B>Unitatea: &nbsp".$_POST["denunit"]."</B>";
	echo "</TD>";
	echo "<TD width=\"160\" class=\"style2\"  height=\"25\" align=\"left\"><B>An scolar: ".$_POST["an"]." - ".$wan2."</B>";
	echo "</TD>";
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td bgcolor=\"white\" colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "</table>";

	echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	echo "<tr>";
	echo "<td colspan=\"20\" height=\"1px\"></td>";
	echo "</tr>";
	echo "</table>";

	echo "<FORM NAME=\"form\" ACTION=\"A21_lista_reg_casa.php\" METHOD=\"POST\" target=\"_blank\">";
	include 'A21_param1.php';		
	
	echo "<TABLE class=\"style1\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";				
	echo "<TR>";
	echo "<TD align=\"center\" class=\"td_print2\">";
	echo "<B>REGISTRU DE CASA</B>";
	echo "<BR>";
	echo "</TD>";
	echo "</TR>";				
	echo "<TR>";
	echo "<TD align=\"center\" class=\"td_print2\">";
	echo "<B>DIN DATA DE: <U>".$_POST["data_reg"]."</U></B>";
	echo "</TD>";
	echo "</TR>";
	echo "</TABLE>";
	
	echo "<BR>";
	
	echo "<TABLE cellSpacing=0 cellPadding=0 width=\"30%; height:100%;\" border=0 align=\"right\">";
	echo "<TR>";
	echo "<TD align=\"right\" height=\"35\">";
	//echo "<input type=\"button\" class=\"noPrint\" onClick=\"window.print()\" value=\"PRINTARE\">";
	echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"LISTARE\">";
	echo "<INPUT TYPE=\"HIDDEN\" NAME=\"data_reg\" value=\"".$_POST["data_reg"]."\">";
	echo "</TD>";
	echo "</FORM>";
	echo "<FORM NAME=\"form\" ACTION=\"A21_copii.php\" METHOD=\"POST\">";
	include 'A21_param1.php';
	echo "<TD align=\"left\" height=\"35\">";
	echo "<input type=\"submit\" class=\"noPrint\" name=\"actiune\" value=\"INAPOI\">";
	//echo "<input type=\"button\" onclick=\"javascript:window.close()\" class=\"noPrint\" value=\"INAPOI\">";
	echo "</TD>";
	echo "</TR>";
	echo "</TABLE>";

	echo "<TABLE cellSpacing=0 cellPadding=0 width=\"90%\" border=0>";
	echo "<BR>";
	echo "<TR BGCOLOR=\"white\">";
	
	echo 	"<TH align=\"center\" width=\"3%\" class=\"td35\">Nr. crt.</TH>";
	echo 	"<TH align=\"center\" width=\"4%\" class=\"td35\">ID</TH>";					
	echo	"<TH align=\"center\" width=\"12%\"  class=\"td35\">Nume Prenume prescolar</TH>";
	echo	"<TH align=\"center\" width=\"12%\" class=\"td35\">Platitor</TH>";	
	echo	"<TH align=\"center\" width=\"7%\" class=\"td35\">Tip doc</TH>";				
	echo	"<TH align=\"center\" width=\"8%\" class=\"td35\">Nr. chitanta</TH>";
	echo	"<TH align=\"center\" width=\"4%\" class=\"td35\">Suma</TH>";
	echo	"<TH align=\"center\" width=\"3%\" class=\"td35\">Anulat</TH>";
	echo	"<TH align=\"center\" width=\"15%\" class=\"td39\">Grupa</TH>";
	echo    "</TR>";
		
	$wdata_reg = date("Y-m-d", strtotime($_POST["data_reg"]));
	$wcodgrp = '00';
	$wtotal = 0;
	$i=1;
	
	$query="SELECT * from chitante WHERE data_doc=\"".$wdata_reg."\" order by nr_doc";
	$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
	
	while($row=mysql_fetch_array($result))
	{
		$query1="SELECT codgrp,codcopil,nume,prenume from copii WHERE codcopil=\"".$row["codcopil"]."\"";
		$result1=mysql_query($query1) or die("Interogare esuata: ".mysql_error());
		$row1=mysql_fetch_array($result1);
		
		$query1_1="SELECT codgrp,dengrp from grupe WHERE codgrp=\"".$row1["codgrp"]."\"";
		$result1_1=mysql_query($query1_1) or die("Interogare esuata: ".mysql_error());
		$row1_1=mysql_fetch_array($result1_1);
		
		$wcodgrp = $row1_1["codgrp"];
		$den_grupa = substr($row1_1["dengrp"], 0, strpos($row1_1["dengrp"], '-'));
				
		IF (empty($den_grupa))
		{
			$den_grupa = $row1_1["dengrp"];
		}
				
		$wcodcopil = $row1["codcopil"];
		$wnume = $row1["nume"];
		$wprenume = $row1["prenume"];
		$wplatitor = $row["platitor"];
			
		IF ($row["anulat"] <> 'X')
		{
			$wtotal = $wtotal + $row["val_doc"];					
		}
	
		$data_doc = date("d-m-Y", strtotime($row["data_doc"]));
		
		if ($i-floor($i/2)*2==0)
		{
			echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
		}
		else
		{
			echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
		}
		
		echo "<TD width=\"3%\" align=\"center\">".$i."</TD>";						
		echo "<TD width=\"4%\" align=\"center\">";
		echo "".$wcodcopil."";
		echo "</TD>";
		echo"<TD width=\"12%\" align=\"left\">";
		echo "<B>&nbsp".trim($wnume)." ".trim($wprenume)."&nbsp</B>";
		echo "</TD>";
		echo"<TD width=\"12%\" align=\"left\">";
		echo "&nbsp".$wplatitor."&nbsp";
		echo "</TD>";		
		echo"<TD width=\"7%\" align=\"center\">";
		echo "&nbsp".$row["tip_doc"]."&nbsp";
		echo "</TD>";				
		if ($row["tip_doc"] === "CHA")
		{
			echo"<TD width=\"8%\" align=\"center\">";
			echo "&nbsp".$row["serie_doc"]."_".$row["nr_doc"]."&nbsp";
			echo "</TD>";
		}
		else
		{				
			echo"<TD width=\"8%\" align=\"center\">";
			echo "&nbsp".$row["nr_doc"]."&nbsp";
			echo "</TD>";
		}
		if ($row["anulat"] === 'X')
		{
			echo"<TD width=\"4%\" align=\"center\">";
			echo "0&nbsp(".$row["val_doc"].")&nbsp";
			echo "</TD>";
		}
		else
		{				
			echo"<TD width=\"4%\" align=\"center\">";
			echo "&nbsp".$row["val_doc"]."&nbsp";
			echo "</TD>";
		}	
		echo"<TD width=\"3%\" align=\"center\">";
		echo "&nbsp".$row["anulat"]."&nbsp";
		echo "</TD>";
		echo"<TD width=\"15%\" align=\"left\">";
		echo "&nbsp".$den_grupa."&nbsp";
		echo "</TD>";		
		echo "</TR>";
		++$i;			
	}

	echo "<TR>";
	echo "<TD colspan=\"9\">&nbsp</TD>";
	echo "</TR>";
	echo "<TR>";
	echo "<TD colspan=\"9\"><HR></HR>&nbsp</TD>";
	echo "</TR>";	
	echo "<TR>";	
	echo "<TD width=\"3%\" align=\"center\">&nbsp</TD>";				
	echo "<TD width=\"4%\" align=\"center\">&nbsp</TD>";
	echo"<TD width=\"15%\" align=\"left\">&nbsp</TD>";
	echo"<TD width=\"15%\" align=\"center\">&nbsp</TD>";
	echo"<TD width=\"3%\" align=\"center\">&nbsp</TD>";
	echo"<TD width=\"8%\" align=\"center\"><B>TOTAL:</B></TD>";
	echo"<TD width=\"4%\" align=\"center\"><B>$wtotal</B></TD>";	
	echo"<TD width=\"3%\" align=\"center\">&nbsp</TD>";
	echo "</TR>";
	
	mysql_close($connection);		
}
?>

</body>
</html>		
					