include_once("../../php5/db_connection.php5");
set_time_limit(0);
$project = $_POST["project"];
$head_tag = $_POST["head_tag"];
$main_table = $project."_".$head_tag;
$id_field = $_POST["id_field"];
$cross_ref_field = $_POST["cross_ref"];
$cross_ref_d_field = $_POST["cross_ref_d"];
$dialect_fields = $_POST["dialect_fields"];
$lines = explode("\n",$dialect_fields);
$dialect_fields = array();
foreach($lines as $line) {
$vals = explode(" = ",$line);
$dialect = trim($vals[0]);
$field = trim($vals[1]);
$dialect_fields[$dialect] = $field;
}
$table = $project."_".$cross_ref_field."group";
$query = "SELECT ".$head_tag."_id,".$cross_ref_field."_0,".$cross_ref_d_field."_0 FROM $table ORDER BY ".$cross_ref_field."_0";
//echo $query."
";
$query_result = mysql_query($query);
$index = 0;
$has_error = false;
$errors = array();
while($row = mysql_fetch_assoc($query_result)){
$value = $row[$cross_ref_field."_0"];
$cross_ref_d = $row[$cross_ref_d_field."_0"];
$main_id = $row[$head_tag."_id"];
foreach($dialect_fields as $dialect=>$field) {
$query = "SELECT count(*) FROM $main_table WHERE ".$field."_0 = \"$value\"";
$r = mysql_query($query);
$vals = mysql_fetch_assoc($r);
$count = $vals["count(*)"];
if(eregi($dialect,$cross_ref_d)) {
if($count < 1) {
$has_error = true;
$message = "dialect is $cross_ref_d but no entry exists with $field=$value";
}
}
else if($count > 0) {
$has_error = true;
$message = "dialect only contains $cross_ref_d but and an entry exists containing $field=$value";
}
if($has_error) {
$query = "SELECT ".$id_field."_0 FROM $main_table WHERE ".$head_tag."_id='$main_id'";
$foo = mysql_query($query);
$id_row = mysql_fetch_assoc($foo);
$id = $id_row[$id_field."_0"];
echo "$id : $message
";
$message = "";
$has_error = false;
}
}
}
?>