a.binder il y a 8 ans
Parent
commit
f597102a4e
1 fichiers modifiés avec 109 ajouts et 0 suppressions
  1. 109 0
      SE/dev/audit_krs_con_digger/audit_krs_con_digger.php

+ 109 - 0
SE/dev/audit_krs_con_digger/audit_krs_con_digger.php

@@ -153,6 +153,115 @@ function add_path($path,$last_tbl) {
 }
 
 
+function sql($hist_loop,$prev_tbl,$prev_dig,$loop,$hist_time,$last_tbl,$path,$table_class) {
+	global $tables;
+	foreach($tables[$table_class] as $Z=>$z) {
+				 	//rels in tbls
+				 	foreach($z['rel'] as $z_rel_from=>$z_rel_to) {
+				 	//	echo "110 test z_rel_fr ".$z_rel_from." to z_rel_to ".$z_rel_to ;
+				 		if( isset($prev_tbl['rel'][$z_rel_from])) {
+					 		if( strlen($prev_dig->$prev_tbl['rel'][$z_rel_from]) > 0  ) {
+						 		$sql[$Z]['rel'][$z_rel_to] = $prev_dig->$prev_tbl['rel'][$z_rel_from];
+						 		$path_rel[$Z][]="(".$z_rel_to.")";
+					 		}
+				 		}
+				 	}
+				 	
+				 	
+				 	//search addr
+				 	if(isset($z['rel_and'])) {
+					 	foreach($z['rel_and'] as $z_rel_and=>$z_rel_and_name) {
+						 	$rel_and_ok=1;
+		
+						 	foreach($z_rel_and_name as $z_rel_and_name_cur=>$z_rel_and_name_col_to) {
+							 	if(isset($prev_dig->$z_rel_and_name_col_to) and ( strlen($prev_dig->$z_rel_and_name_col_to)) > 0  ) {//and ( strlen($prev_dig->$z_rel_and_name_cur) > 2) 
+								 	if($rel_and_ok<>0) $rel_and_ok=2;
+								// 	echo "\n<br>121 rel_and from:".$last_tbl." OK for tbl ".$Z." z_rel_and_name_col_to: ".$z_rel_and_name_col_to." value:".$prev_dig->$z_rel_and_name_cur." rel_and_ok=".$rel_and_ok;
+								} else {
+							//	 	echo "<br> #127 UNSET ".$prev_dig->$z_rel_and_name_cur." / ".$z_rel_and_name_col_to." ";
+								 	$rel_and_ok=0;
+								}
+						 	}
+
+						  if($rel_and_ok==2) {
+							  $path_rel_and = array();
+						//	  echo "\n<br>#133 Z=".$Z." ok rel_and_ok=".$rel_and_ok;
+							  foreach($z_rel_and_name as $z_rel_and_name_cur=>$z_rel_and_name_col_to) {
+						//		  echo "\n<br> 135... ok. Z=".$Z."/ z_rel_and_name=".$z_rel_and_name_cur."/ z_rel_and_name_col_to=".$z_rel_and_name_col_to."/ prev_dig-z_rel_and_name_cur=".$prev_dig->$z_rel_and_name_cur;
+							  	$sql_rel_and[$Z][$z_rel_and][$z_rel_and_name_col_to]=$prev_dig->$z_rel_and_name_col_to;
+							  	$path_rel_and[]="(".$z_rel_and_name_col_to.")";
+							  }
+						  } else {
+							//  echo "<br>#137 error rel_and_ok=".$rel_and_ok;
+						  }
+					 	}
+					 	
+				 	}
+			 }
+	
+	
+	
+	if( isset($sql_rel_and)) {
+			foreach($sql_rel_and as $T=>$z_rel_and_arr) {
+				foreach($z_rel_and_arr as $z_rel_and_name=>$z_rel_and_name_col) {
+					//echo "<br>156 z_rel_and_name=".$z_rel_and_name." ";
+					$sql_rel_and_sql[$T][$z_rel_and_name]="select * from ".$T." where ( ";
+					$and=0;
+					foreach($z_rel_and_name_col as $z_rel_and_name_cur=>$z_rel_and_name_col_to) {
+						if( $and==1) $sql_rel_and_sql[$T][$z_rel_and_name].=" and  `".$z_rel_and_name_cur."` = '".$z_rel_and_name_col_to."' and `".$z_rel_and_name_cur."` not like '%--%' and   `".$z_rel_and_name_cur."` not like '' " ;
+						else $sql_rel_and_sql[$T][$z_rel_and_name].="  `".$z_rel_and_name_cur."` like '".$z_rel_and_name_col_to."' and `".$z_rel_and_name_cur."` not like '%--%' and   `".$z_rel_and_name_cur."` not like ''  " ;
+					//	if($z_rel_and_name_cur=='miejscowosc') $sql_rel_and_sql[$T][$z_rel_and_name].=" and `miejscowosc` not like '' " ; 
+					//	if($z_rel_and_name_cur=='A_ulica') $sql_rel_and_sql[$T][$z_rel_and_name].=" and `A_ulica` not like '' " ; 
+					//	if($z_rel_and_name_cur=='ulica') $sql_rel_and_sql[$T][$z_rel_and_name].=" and `ulica` not like '' " ; 						
+					//	if($z_rel_and_name_cur=='kodPocztowy') $sql_rel_and_sql[$T][$z_rel_and_name].=" and `kodPocztowy` not like '' " ; 						
+					//	if($z_rel_and_name_cur=='budynek') $sql_rel_and_sql[$T][$z_rel_and_name].=" and `budynek` like '".$z_rel_and_name_col_to."' " ; 	
+					//	if($z_rel_and_name_cur=='A_nrDomu') $sql_rel_and_sql[$T][$z_rel_and_name].=" and `A_nrDomu` like '".$z_rel_and_name_col_to."' " ; 	
+					//	if($z_rel_and_name_cur=='kodPocztowy') $sql_rel_and_sql[$T][$z_rel_and_name].=" and `kodPocztowy` like '".$z_rel_and_name_col_to."' " ; 							
+						
+											
+						$and=1;
+					}
+					$sql_rel_and_sql[$T][$z_rel_and_name].="  ) " ;
+					if( isset($hist_loop[$T])) {
+					 	 foreach($hist_loop[$T] as $hist_rec) {
+						 	 $sql_rel_and_sql[$T][$z_rel_and_name].=" and ID!='".$hist_rec->ID."' ";
+					 	 }
+				 	 }
+					$sql_rel_and_sql[$T][$z_rel_and_name].=" ; " ;
+				 	 dig_arr_cur($hist_loop,$T,$sql_rel_and_sql[$T][$z_rel_and_name],$hist_time,$loop,$last_tbl,$path);
+				}
+			}	  
+			  
+		}
+		
+		if(isset($sql)) {
+			foreach($sql as $T => $rel) {
+					 	 $sql_t[$T]=" select * from ".$T." where ( ";
+					 	 foreach($rel['rel'] as $col=>$val) {
+						 	 if( isset($sql_t_str[$T]))  $sql_t_str[$T].=" or `".$col."` = '".$val."' " ;
+						 	 else $sql_t_str[$T]=" `".$col."` = '".$val."' " ;
+					 	 }
+					 	 $sql_t[$T].=$sql_t_str[$T]." ) ";
+					 	 //not loop
+					 	 if( isset($hist_loop[$T])) {
+						 	 echo "<br> hist loop cnt: ". count($hist_loop[$T]);
+						 	 foreach($hist_loop[$T] as $hist_rec) {
+							 	 $sql_t[$T].=" and ID!='".$hist_rec->ID."' ";
+						 	 }
+					 	 }
+					 	 
+				 	 }
+		
+				 	 if( isset($sql_t)) {
+					  foreach($sql_t as $T => $sql_ext)  { 
+						 // $path.=$path_rel[$T][ key($sql_ext) ];
+						  dig_arr_cur($hist_loop,$T,$sql_ext,$hist_time,$loop,$last_tbl,$path);
+					  }
+				  }
+		}
+	
+}
+
 
 function dig_next($hist_loop,$prev_tbl,$prev_dig,$loop,$hist_time,$last_tbl='n/s',$path) {
 	 global $db,$tables;