<?php

function ANALIZA_HISTORII_ALL() {
	global $result;

	SE_Layout::menu();

	$_GET['F_LIMIT'] = V::get('F_LIMIT', 50, $_GET, 'int');
	$_GET['TABLES_LIKE'] = V::get('TABLES_LIKE', '', $_GET);
	$_GET['A_RECORD_UPDATE_DATE']  = V::get('A_RECORD_UPDATE_DATE', '', $_GET);
	$_GET['A_RECORD_UPDATE_DATE2'] = V::get('A_RECORD_UPDATE_DATE2', '', $_GET);
	$_GET['A_RECORD_UPDATE_AUTHOR']  = V::get('A_RECORD_UPDATE_AUTHOR', '', $_GET);
	$_GET['A_RECORD_UPDATE_AUTHOR2'] = V::get('A_RECORD_UPDATE_AUTHOR2', '', $_GET);
	$REBUILD_ANALIZA_HISTORII_ALL_TABLE = V::get('REBUILD_ANALIZA_HISTORII_ALL_TABLE', '', $_GET);
	
	
	$__install = V::get('__install', '', $_GET);

	$db = DB::getDB();











Lib::LoadClass('InstallerHelper') ;



	if(!empty($__install)) { 
	//TODO example
	 $installer=new InstallerHelper(); //('new_parent_option','NEW_TABLE');
	 $new_MYSQL_SCHEMA = $installer->new_child('MYSQL_SCHEMA');
		 $new_table = $new_MYSQL_SCHEMA->new_child('TABLES');
		 	$new_table->set_option('Table_type','BASE TABLE');
		 	$new_table->set_option('NAME','_ANALIZA_HISTORII_ALL');

		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','ID');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','PRI');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('int');
		 			$new_table_field_id_int->set_option('M','11');


	 	DEBUG_S(-3,'new_table_field',$new_table_field);

		// 		unset($new_table_field);unset($new_table_field_id);unset($new_table_field_id_int);

		 		$new_table_field = $new_table->new_child('FIELDS');

		 		$new_table_field->set_option('Field','TABLE_NAME');
		 		

		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('varchar');
		 			$new_table_field_id_int->set_option('M','255');		 	

		 DEBUG_S(-3,'new_table_field',$new_table_field);


		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','TABLE_ID');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('int');
		 			$new_table_field_id_int->set_option('M','11');		 	
   				
 		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','FIELD');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('varchar');
		 			$new_table_field_id_int->set_option('M','255');		 	

   				
 		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','VALUE_OLD');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('text');
   				
   							  							
		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','VALUE');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('text');
   			
	

 
		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','A_RECORD_UPDATE_DATE');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('varchar');
		 			$new_table_field_id_int->set_option('M','30');		 	

		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','A_RECORD_UPDATE_AUTHOR');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('varchar');
		 			$new_table_field_id_int->set_option('M','100');		 	


		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','A_RECORD_CREATE_DATE');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('varchar');
		 			$new_table_field_id_int->set_option('M','30');		 	

		 		$new_table_field = $new_table->new_child('FIELDS');
		 		$new_table_field->set_option('Field','A_RECORD_CREATE_AUTHOR');
		 		$new_table_field->set_option('Null','NO');
		 		$new_table_field->set_option('Key','');
		 		$new_table_field->set_option('Default','');
		 		$new_table_field->set_option('Extra','auto_increment');
		 		$new_table_field_id = $new_table_field->new_child('Type');
		 			$new_table_field_id_int = $new_table_field_id->new_child('varchar');
		 			$new_table_field_id_int->set_option('M','100');		 	

  		
  		
		 		$new_table_index = $new_table->new_child('INDEX');
		 		$new_table_index->set_option('Key_name','TABLE_NAME');
		 		
		 		$new_table_index_col = $new_table_index->new_child('Column_name');
		 			$new_table_index_col->set_option('column','TABLE_NAME');
		 		$new_table_index_col = $new_table_index->new_child('Column_name');
		 			$new_table_index_col->set_option('column','TABLE_ID');
		 		$new_table_index_col = $new_table_index->new_child('Column_name');
		 			$new_table_index_col->set_option('column','FIELD');

		



//	 $new_table_index = $new_table->new_child('INDEX');

//	 $new_table_field = $new_table_field->set_option('TABLE_FIELD_TYPE','INT');
//
//	 $new_table_field = $new_table->new_child('TABLE_FIELD');
//	 $new_table_field = $new_table_field->set_option('TABLE_FIELD_NAME','A_RECORD_UPDATE_DATE');
//	 $new_table_field = $new_table_field->set_option('TABLE_FIELD_TYPE','VARCHAR');
//	 $new_table_field = $new_table_field->set_option('TABLE_FIELD_LENGHT','100');

	
	// $new_table->NEW_TABLE('dupa');





	 
	 	DEBUG_S(-3,'installer',$installer);
	 	DEBUG_S(-3,'new_MYSQL_SCHEMA',$new_MYSQL_SCHEMA);
	 	DEBUG_S(-3,'new_table',$new_table);
	 	DEBUG_S(-3,'new_table_field',$new_table_field);
	 	
	// 	DEBUG_S(-3,'new_table',$new_table);

	//$install->__add_req_option('table');
	$installer->__install();
	
	//$table->get_options_status();
	
	//var_dump($install);
	
   	 //InstallerHelper::__install();
   	 
   	 die('umarlem');
	
	}



Lib::loadClass('ProcesHelper');
$zasob_tabeli_hist=ProcesHelper::getZasobTableID('_ANALIZA_HISTORII_ALL');

?>
ANALIZA_HISTORII_ALL <form action='' METHOD='GET'>
<input type="hidden" name="ADD" value="ADD">
<input type="hidden" name="MENU_INIT" value="ANALIZA_HISTORII_ALL">
Czy odbudować na nowo tabelę _ANALIZA_HISTORII_ALL ?<input type="checkbox" name="REBUILD_ANALIZA_HISTORII_ALL_TABLE"> 

<a href=index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $zasob_tabeli_hist; ?> >Przeglądanie</a>


<br>Czy zainstalować moduł _ANALIZA_HISTORII_ALL ?<input type="checkbox" name="__install"> 

<table border=1>
	<tr>
		<td>Dodaj Lancuch dla poszukiwan okresu , (zakoncz znakiem %) - 500 rekordow</td>
		<td><input type="text" name="A_RECORD_UPDATE_DATE" size="10" value="<?php echo $_GET['A_RECORD_UPDATE_DATE']; ?>"></td>
		<td><input type="text" name="A_RECORD_UPDATE_DATE2" size="10" value="<?php echo $_GET['A_RECORD_UPDATE_DATE2']; ?>"></td>
		<td><input type="text" name="A_RECORD_UPDATE_AUTHOR"  size="10" value="<?php echo $_GET['A_RECORD_UPDATE_AUTHOR']; ?>"></td>
		<td><input type="text" name="A_RECORD_UPDATE_AUTHOR2"  size="10" value="<?php echo $_GET['A_RECORD_UPDATE_AUTHOR2']; ?>"></td>
		<td><input type="text" name="TABLES_LIKE"  size="10" value="<?php echo $_GET['TABLES_LIKE']; ?>"></td>
		<td><input type="text" name="F_LIMIT"  size="10" value="<?php echo $_GET['F_LIMIT']; ?>"></td>
	</tr>
	<tr>
		<td colspan=1><input type="submit" name="ADD" value="SZUKAJ"></td>
		<td>DATA (np. 2007-%)</td>
		<td>.. lub data DATA (np. 2008-%)</td>
		<td>Autor (np. %sqix%)</td>
		<td>Autor2</td>
		<td>TABELE</td>
	</tr>
	
	</table>
	

<?php
/*

    
$ZAP_SQL="SELECT  t2.* FROM USERS2_DEALS as t2 where
		  t2.A_RECORD_CREATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."' and
		  ( t2.A_RECORD_CREATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR']."' or  t2.A_RECORD_UPDATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."'  ) ";
		if($_GET['A_RECORD_UPDATE_DATE']) ZAP_SQL($ZAP_SQL);
		
//		echo $ZAP_SQL."\n<br>";
 while($DWA=mysql_fetch_object($result)) {
      foreach ($DWA as $DWA_A=>$DWA_V ) {
  		 if((($DWA_V!='')&&($DWA_V!='0'))&&($DWA_A!=$AR)||($DWA_V=='S_ADDRESS_STREET_t1')) {
        	//echo "<td> ".str_replace('_',' ',$DWA_A)." = $DWA_V </td>";   
	    	$ARR[STAT][$DWA->A_RECORD_CREATE_AUTHOR][$DWA_A]++;
            if($DWA_A=='A_RECORD_CREATE_AUTHOR') $ARR[AUTH][$DWA_V]++;
     	 }
     if($DWA_A==$AR)$AR++;
     }
    }

//print_r($ARR);
unset($ARR);

*/

	$RAPORT['IGNORE_TABLES'][] = "AUTOSHAPE";

	//echo statystyka pracy historyczna w systemie 
	$dbTbls = array();
	$ZAP_SQL = "show tables ";
	if (!empty($_GET['TABLES_LIKE'])) {
		$ZAP_SQL .= " like '{$_GET['TABLES_LIKE']}' ";
	}
	$res = $db->query($ZAP_SQL);
	while($R = $db->fetch_array($res)) {
		$dbTbls[] = $R;
	}
	foreach ($dbTbls as $R) {
		if (!in_array($R[0], $RAPORT['IGNORE_TABLES'])) {
			$RAPORT['TABLES_ALL'][] = $R[0];
		}
	}
	foreach ($dbTbls as $R) {
		if (strstr($R[0], "_HIST")) {
			$RAPORT['TABLES_HIST'][$R[0]]['TABLE_HIST'] = $R[0];
			$tblName = str_replace("_HIST", "", $R[0]);
			if (in_array($tblName, $RAPORT['TABLES_ALL'])) {
				$RAPORT['TABLES_HIST'][$R[0]]['TABLE'] = $tblName;
			}
		}
	}
	unset($dbTbls);

	$ZAP_SQL = array();
	$ZAP_SQL['TABLES'] = array();
	
	if(!empty($REBUILD_ANALIZA_HISTORII_ALL_TABLE)) { 

		
		//$sql="truncate table _ANALIZA_HISTORII_ALL_TABLE";
		DEBUG_S(-3,"Odbudowa tabeli analiz _ANALIZA_HISTORII_ALL_TABLE",$sql,__FILE__,__FUNCTION__,__LINE__);
		//DB::query($sql);
		
	}

	
	
	foreach ($RAPORT['TABLES_HIST'] as $RTH_I=>$RTH_A) {
		if (isset($RTH_A['TABLE'])) {
			$res = $db->query("select * from ".$RTH_A['TABLE']." limit 1");
			$r2 = $db->fetch_array($res);
			if (isset($r2['A_RECORD_CREATE_AUTHOR']) && isset($r2['A_RECORD_CREATE_DATE'])
					&& isset($r2['A_RECORD_UPDATE_DATE']) && isset($r2['A_RECORD_UPDATE_AUTHOR'])
					&& isset($r2['ID'])) {
					
				//dobudowanie tabeli 	_ANALIZA_HISTORII_ALL
				
					
					
					
					
					
					
				if (isset($r2['T_WORKPOINTS_USER']) && isset($r2['T_WORKPOINTS_DATE'])) {
					$sql = "SELECT  A_RECORD_CREATE_DATE as C1
							, year(A_RECORD_CREATE_DATE) as C1_Y
							, month(A_RECORD_CREATE_DATE) as C1_M
							, day(A_RECORD_CREATE_DATE) as C1_D
							,  A_RECORD_CREATE_AUTHOR as C2
							, ID as TAB_ID
							, '".$RTH_A['TABLE']."' as TABLEE
						from ".$RTH_A['TABLE']." as C2
						where
							( A_RECORD_CREATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."' or A_RECORD_CREATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE2']."' )
							and ( A_RECORD_CREATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR']."'  or  A_RECORD_CREATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."' )
					";
if(V::get('DBG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
					$ZAP_SQL['TABLES'][] = $sql;
					//workpoints table
					$sql = "SELECT  T_WORKPOINTS_DATE as C1
							, year(T_WORKPOINTS_DATE) as C1_Y
							, month(T_WORKPOINTS_DATE) as C1_M
							, day(T_WORKPOINTS_DATE) as C1_D
							, T_WORKPOINTS_USER as C2
							, ID as TAB_ID
							, '".$RTH_A['TABLE']."_WP' as TABLEE
						from ".$RTH_A['TABLE']." as C2
						where
							( T_WORKPOINTS_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."' or T_WORKPOINTS_DATE like '".$_GET['A_RECORD_UPDATE_DATE2']."' )
							and ( T_WORKPOINTS_USER like '".$_GET['A_RECORD_UPDATE_AUTHOR']."' or  T_WORKPOINTS_USER like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."' )
					";
if(V::get('DBG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
					$ZAP_SQL['TABLES'][] = $sql;
				}
				else {
					$sql = "SELECT  A_RECORD_CREATE_DATE as C1
							, year(A_RECORD_CREATE_DATE) as C1_Y
							, month(A_RECORD_CREATE_DATE) as C1_M
							, day(A_RECORD_CREATE_DATE) as C1_D
							, A_RECORD_CREATE_AUTHOR as C2
							, ID as TAB_ID
							, '".$RTH_A['TABLE']."' as TABLEE
						from ".$RTH_A['TABLE']." as C2
						where
							A_RECORD_CREATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."'
							and ( A_RECORD_CREATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR']."' or A_RECORD_CREATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."' )
					";
if(V::get('DBG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
					$ZAP_SQL['TABLES'][] = $sql;
				}

				$sql = "SELECT  A_RECORD_CREATE_DATE as C1
						, A_RECORD_CREATE_AUTHOR
						, ID as TAB_ID
						, '".$RTH_A['TABLE']."' as TABLEE
					from ".$RTH_A['TABLE']." as C2
					where
						( A_RECORD_CREATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."' or A_RECORD_CREATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE2']."' )
						and ( A_RECORD_CREATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR']."' or A_RECORD_CREATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."' )
				";
				//$res = $db->query($sql); 
			}
		}

		$res = $db->query("select * from ".$RTH_A['TABLE_HIST']." limit 1");
		$r2 = $db->fetch_array($res);
		$res = null;
		if (isset($r2['A_RECORD_CREATE_AUTHOR']) && isset($r2['A_RECORD_CREATE_DATE'])
				&& isset($r2['A_RECORD_UPDATE_DATE']) && isset($r2['A_RECORD_UPDATE_AUTHOR'])
				&& isset($r2['ID_USERS2'])) {
			if(isset($r2['T_WORKPOINTS_USER']) && isset($r2['T_WORKPOINTS_DATE'])) {
				$sql = "SELECT  A_RECORD_UPDATE_DATE as C1
						, year(A_RECORD_UPDATE_DATE) as C1_Y
						, month(A_RECORD_UPDATE_DATE) as C1_M
						, day(A_RECORD_UPDATE_DATE) as C1_D
						, A_RECORD_UPDATE_AUTHOR as C2
						, ID_USERS2 as TAB_ID
						, '".$RTH_A['TABLE_HIST']."' as TABLEE
					from ".$RTH_A['TABLE_HIST']."
					where
						( A_RECORD_UPDATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."' or A_RECORD_UPDATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE2']."' )
						and ( A_RECORD_UPDATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR']."' or A_RECORD_UPDATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."' )
				";
if(V::get('DBG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
				$ZAP_SQL['TABLES'][] = $sql;

				//workpoints
				$sql = "SELECT T_WORKPOINTS_DATE as C1
						, year(T_WORKPOINTS_DATE) as C1_Y
						, month(T_WORKPOINTS_DATE) as C1_M
						, day(T_WORKPOINTS_DATE) as C1_D
						, A_RECORD_UPDATE_AUTHOR as C2
						, ID_USERS2 as TAB_ID
						, '".$RTH_A['TABLE_HIST']."_WP' as TABLEE
					from ".$RTH_A['TABLE_HIST']."
					where
						( T_WORKPOINTS_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."'  or T_WORKPOINTS_DATE like '".$_GET['A_RECORD_UPDATE_DATE2']."' )
						and ( T_WORKPOINTS_USER like '".$_GET['A_RECORD_UPDATE_AUTHOR']."' or T_WORKPOINTS_USER like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."' )
				";
if(V::get('DBG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
				$ZAP_SQL['TABLES'][] = $sql;
				$res = $db->query($sql);
			}
			else {
				$sql = "SELECT
						A_RECORD_UPDATE_DATE as C1
						,  year(A_RECORD_UPDATE_DATE) as C1_Y
						, month(A_RECORD_UPDATE_DATE) as C1_M
						, day(A_RECORD_UPDATE_DATE) as C1_D
						, A_RECORD_UPDATE_AUTHOR as C2
						, ID_USERS2 as TAB_ID
						, '".$RTH_A['TABLE_HIST']."' as TABLEE
					from ".$RTH_A['TABLE_HIST']."
					where
						(
							A_RECORD_UPDATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."'
							or A_RECORD_UPDATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE2']."'
						) and (
							A_RECORD_UPDATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR']."'
							or A_RECORD_UPDATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."'
						)
				";
if(V::get('DBG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
				$ZAP_SQL['TABLES'][] = $sql;
				$res = $db->query($sql);
			}
			
				$ignore_tables=array('CRM_TESTY_ODPOWIEDZI','CRM_TESTY_ODPOWIEDZI_HIST');
				if(!in_array($RTH_A['TABLE_HIST'], $ignore_tables))
				if(!empty($REBUILD_ANALIZA_HISTORII_ALL_TABLE)) { 
				$sql="select * from ".$RTH_A['TABLE_HIST']."  where
						(
							A_RECORD_UPDATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."'
							or A_RECORD_UPDATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE2']."'
						) and (
							A_RECORD_UPDATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR']."'
							or A_RECORD_UPDATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR2']."'
						)
						
						";
						//echo "<br>".$sql;
						
					$resa=DB::query($sql);
					$index_fields=array('ADM_PASSWD'=>'ADM_PASSWD','ID_USERS2'=>'ID_USERS2','A_RECORD_UPDATE_DATE'=>'A_RECORD_UPDATE_DATE','A_RECORD_UPDATE_AUTHOR'=>'A_RECORD_UPDATE_AUTHOR','A_RECORD_CREATE_AUTHOR'=>'A_RECORD_CREATE_AUTHOR','A_RECORD_CREATE_DATE'=>'A_RECORD_CREATE_DATE','ID'=>'ID');
					while($h=DB::fetch($resa)) {
						
						//print_r($h);
						$sql="";if(isset($sql_obj)) unset($sql_obj);
						foreach($h as $field=>$value) {
							if(in_array($field, $index_fields)) {
								
							} else {
								if(($value!='N/S;')) {
								if(strlen($value>10000)) $value='DATA OVER 10000bytes';
								$sql="insert ignore into _ANALIZA_HISTORII_ALL( TABLE_NAME, TABLE_ID,FIELD,VALUE,A_RECORD_CREATE_DATE,A_RECORD_CREATE_AUTHOR,A_RECORD_UPDATE_DATE,A_RECORD_UPDATE_AUTHOR ) values (
								  '{$RTH_A['TABLE_HIST']}','{$h->ID}','{$field}','".DB::_($value)."','{$h->A_RECORD_CREATE_DATE}','{$h->A_RECORD_CREATE_AUTHOR}','{$h->A_RECORD_UPDATE_DATE}','{$h->A_RECORD_UPDATE_AUTHOR}' )";
								  //echo "<br>".$sql;
								  DB::query($sql) or die($sql);
								  }
								
							}
							//die();

							
							
						}

					}
					
				
				}
			
			
			
			
		}
		else {
			$NIE_MA[]="Nie ma w tab ".$RTH_A['TABLE_HIST']."  kolumn . .";
		}
	}

	DEBUG_S(-3,'Brakuje tabel',$NIE_MA,__FILE__,__FUNCTION__,__LINE__);
	$ZAP_SQL['SQL'] = implode(' union ', $ZAP_SQL['TABLES']);
	$ZAP_SQL['SQL'] .= " order by date(C1) ";

	if ($_GET['A_RECORD_UPDATE_DATE']) {
		$res = $db->query($ZAP_SQL['SQL']);
	}

	$ARR = array();
	if ($res) {
		while ($DWA = $db->fetch($res)) {
if(V::get('DBG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$DWA (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($DWA);echo'</pre>';}
			$ARR['STAT'][$DWA->C2][$DWA->TABLEE]++;
			//czysczenie formatow dat:
			list($DAT_L1, $DAT_L2) = explode(" ", $DWA->C1);
			$DWA->C1 = (isset($DAT_L2))? $DAT_L1 . "-" . $DAT_L2 : $DWA->C1 . ":00";

			$ARR['DATE'][$DWA->C2][$DWA->C1] = $DWA->TABLEE . " : " . $DWA->TAB_ID;
			$ARR['DATE_CHART'][$DWA->C2][$DWA->C1_Y][$DWA->C1_M][$DWA->C1_D]['COUNT']++;
			$C1_H = substr($DWA->C1, 11, 2);
			$ARR['DATE_CHART'][$DWA->C2][$DWA->C1_Y][$DWA->C1_M][$DWA->C1_D]['HOURS'][$C1_H]++;
			$ARR['DATE_CHART'][$DWA->C2][$DWA->C1_Y][$DWA->C1_M][$DWA->C1_D]['TABLE'][$DWA->TABLEE]++;
			$ARR['AUTH'][$DWA->C2]++;
			#if ($DWA_A == $AR) {
			#	$AR++;
			#}
		}
	}
if(V::get('DBG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$ARR (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($ARR);echo'</pre>';}

	$_SESSION['CHART']['ARR'] = $ARR;
	$_SESSION['CHART']['TITLE'] = "COSTAM SQIX TITLE";
	unset($ARR);

	$pok_gif = "puste";
	$cnt = 0;
	$data_table = array();
	$data_hours = array();
	if (isset($_SESSION['CHART']['ARR']['DATE_CHART']) && is_array($_SESSION['CHART']['ARR']['DATE_CHART'])) {
		foreach($_SESSION['CHART']['ARR']['DATE_CHART'] as $C2=>$C2V) {
			$i = 0;
			$cnt++;

			foreach ($C2V as $C1_Y=>$C1_YV) {
				foreach ($C1_YV as $C1_M=>$C1_MV) {
					foreach ($C1_MV as $C1_D=>$C1_DV) {
						$data[$C2][$C1_D] = $C1_DV['COUNT'];
						$i += $C1_DV['COUNT'];

						//hours
						foreach ($C1_DV['HOURS'] as $C1_H=>$C1_HV) {
							$data_hours[$C2][$C1_H] += $C1_HV;
						}
						foreach ($C1_DV['TABLE'] as $C1_H=>$C1_HV) {
							$data_table[$C2][$C1_H] += $C1_HV;
						}
					}
				}
			}

			if ($i > $_GET['F_LIMIT']) {
				if ($pok_gif == "puste") {
					$pok_gif = $C2;
				} else {
					echo "<br><img src=index.php?MENU_INIT=GRAPH&HEADER_NOT_INIT=YES&type=&C2=".urlencode($C2)."&C22=".urlencode($pok_gif).">";
					echo "<br><img src=index.php?MENU_INIT=GRAPH&HEADER_NOT_INIT=YES&type=HOUR&C2=".urlencode($C2)."&C22=".urlencode($pok_gif).">";
					echo "<br><img src=index.php?MENU_INIT=GRAPH&HEADER_NOT_INIT=YES&type=TABLE&C2=".urlencode($C2)."&C22=".urlencode($pok_gif).">";
					$pok_gif = "puste";
				}
			}	
			echo "\n SIze dla ".$C2." wynioslo ".$i;
		}
	}

	if ($pok_gif != "puste") {
		echo "<br><img src=index.php?MENU_INIT=GRAPH&HEADER_NOT_INIT=YES&type=&C2=".urlencode($pok_gif).">";
		echo "<br><img src=index.php?MENU_INIT=GRAPH&HEADER_NOT_INIT=YES&type=HOUR&C2=".urlencode($pok_gif).">";
		echo "<br><img src=index.php?MENU_INIT=GRAPH&HEADER_NOT_INIT=YES&type=TABLE&C2=".urlencode($pok_gif).">";
	}
	// echo "<br><img src=index.php?MENU_INIT=GRAPH&HEADER_NOT_INIT=YES&type=&C2=".urlencode($pok_gif).">";

	//tabela z godzinami pracy
	foreach ($data_hours as $user_i=>$user) {
		foreach ($user as $TABLEE_I=>$TABLE_V) {
			foreach ($data_hours as $test_user_i=>$test_user_v) {
				if (!isset($test_user_v[$TABLEE_I])) {
					$data_hours[$test_user_i][$TABLEE_I]=0;
				}
			}
		}

		echo "\n data :\n".$user_i;
		ksort($data_hours[$user_i]);
	}

	//$data_table - to dane w jakich tabelach byla praca
	//Tutaj trzeba dodac brakujace do TABLE dane z innych array i posortowac dla dobrego wyswietlenia
	foreach ($data_table as $user_i=>$user) {
		foreach ($user as $TABLEE_I=>$TABLE_V) {
			foreach ($data_table as $test_user_i=>$test_user_v) {
				if (!isset($test_user_v[$TABLEE_I])) {
					//echo "\n W user ".$test_user_i." tabeli ".$TABLEE_I." brakuje!";
					$data_table[$test_user_i][$TABLEE_I]=0;
				}
			}
		}

		ksort($data_table[$user_i]);
	}

	//Sortujemy i uzupelniamy daty prac o brakujace indeksy
	if (isset($_SESSION['CHART']['ARR']['DATE_CHART']) && is_array($_SESSION['CHART']['ARR']['DATE_CHART'])) {
		foreach ($_SESSION['CHART']['ARR']['DATE_CHART'] as $user_i=>$user) { //lecimy ARR[User]
			foreach ($user as $TABLEE_I=>$TABLE_V) { //Lecimy ARR[User][Rok]
				foreach ($TABLE_V as $TABLEE_II=>$TABLE_VV) { //Lecimy ARR[User][Rok][m-c]
					foreach ($TABLE_VV as $TABLEE_III=>$TABLE_VVV) { //Lecimy ARR[User][Rok][m-c][day]
						foreach ($_SESSION['CHART']['ARR']['DATE_CHART'] as $test_user_i=>$test_user_v) { //arr[user]
							if (!isset($test_user_v[$TABLEE_I][$TABLEE_II][$TABLEE_III])) {
								$_SESSION['CHART']['ARR']['DATE_CHART'][$test_user_i][$TABLEE_I][$TABLEE_II][$TABLEE_III]['COUNT']=0;
							}
						}
					}
				}
			}
		}

		foreach($_SESSION['CHART']['ARR']['DATE_CHART'] as $user_i=>$user) { //lecimy ARR[User]
			ksort($_SESSION['CHART']['ARR']['DATE_CHART'][$user_i]);
			foreach($user as $TABLEE_I=>$TABLE_V) { //Lecimy ARR[User][Rok]
				ksort($_SESSION['CHART']['ARR']['DATE_CHART'][$user_i][$TABLEE_I]);
				foreach($TABLE_V as $TABLEE_II=>$TABLE_VV) { //Lecimy ARR[User][Rok][m-c]
					ksort($_SESSION['CHART']['ARR']['DATE_CHART'][$user_i][$TABLEE_I][$TABLEE_II]);
					foreach($TABLE_VV as $TABLEE_III=>$TABLE_VVV) { //Lecimy ARR[User][Rok][m-c][day]
						ksort($_SESSION['CHART']['ARR']['DATE_CHART'][$user_i][$TABLEE_I][$TABLEE_II][$TABLEE_III]);
					}
				}
			}
		}
	}
}
