Tryag File Manager
Home
-
Turbo Force
Current Path :
/
home
/
cluster1
/
data
/
bu01
/
1121861
/
html
/
old_jlex_versions
/
beta
/
2005-08-04 php4
/
Upload File :
New :
File
Dir
/home/cluster1/data/bu01/1121861/html/old_jlex_versions/beta/2005-08-04 php4/add_database.php4~
<? include_once "schema_discoverer.php4"; //include_once "flat_to_hierarchy_converter.php4"; include_once "db_loader.php4"; include_once "schema_checker.php4"; include_once "db_modifier.php4"; include_once "schema_loader.php4"; set_time_limit(0); session_start(); $function = strtolower($_POST["function"]); if($function == "get_fields") { $database = strtolower($_POST["database"]); $db_file = $_POST["db_file"]; $head_tag = $_POST["head_tag"]; $symbols = $_POST["symbols"]; $first_chars = $_POST["first_chars"]; $db_modifier = new db_modifier(); $db_modifier->get_fields($db_file,$head_tag,$symbols,$first_chars); $vars = $_POST; $vars["fields"] = $db_modifier->fields; $vars["strippable_fields"] = $db_modifier->strippable_fields; $_SESSION["vars"] = $vars; if(file_exists("../$database/schema.xml")) { $sl = new schema_loader(); $group = $sl->create_group_structure("../$database/schema.xml",""); $existing_fields = array_merge($group->get_field_names(),$group->get_group_names()); } else { $existing_fields = array(); } $xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; $xml .= "<?xml-stylesheet href='../lex/make_fields_form.xsl' type='text/xsl'?>"; $xml .= "<fields>\n"; foreach($db_modifier->fields as $field) { $xml .= "<field>\n<name>$field</name>\n"; if(in_array($field,$existing_fields)) { $xml .= "<existed>1</existed>\n"; } else { $xml .= "<existed>0</existed>\n"; } if(in_array($field,$db_modifier->strippable_fields)) { $xml .= "<strippable>1</strippable>\n"; if(in_array($field."_s",$existing_fields)) { $xml .= "<existed_s>1</existed_s>\n"; } else { $xml .= "<existed_s>0</existed_s>\n"; } } else { $xml .= "<strippable>0</strippable>\n"; } $xml .= "</field>\n"; } $xml .= "</fields>"; header("Content-Type: application/xml"); echo $xml; } else if($function == "modify") { echo "function: $function<BR>"; $vars = $_SESSION["vars"]; $sort_fields = strtolower($vars["sort_fields"]); $head_tag = strtolower($vars["head_tag"]); $database = strtolower($vars["database"]); $symbols = $vars["symbols"]; $first_chars = $vars["first_chars"]; $fields = $vars["fields"]; $strippable_fields = $vars["strippable_fields"]; $db_file = $vars["db_file"]; $format_type = strtolower($vars["format_type"]); $schema = $vars["schema"]; $new_database_name = $vars["new_database_name"]; $alpha_symbols = $vars["alpha_symbols"]; $alpha_first_chars = $vars["alpha_first_chars"]; $not_include = array(); if(array_key_exists("not_include",$_POST)) { $not_include = $_POST["not_include"]; } $fields_not_to_strip = array(); if(array_key_exists("fields_not_to_strip",$_POST)) { $fields_not_to_strip = $_POST["fields_not_to_strip"]; } $fields = array_diff($fields,$not_include); $strippable_fields = array_diff($strippable_fields,$not_include,$fields_not_to_strip); if(!(($not_include == "") && ($fields_not_to_strip == "") && ($sort_fields == ""))) { $new_name = "modified_".$db_file; $db_modifier = new db_modifier(); $db_modifier->modify($db_file,$new_name,$head_tag, $sort_fields,$alpha_symbols, $alpha_first_chars, $symbols,$first_chars,$fields,$strippable_fields); $db_file = $new_name; } $path = "../$database"; if(!file_exists($path)) { mkdir($path,0755); } $errors = array(); if($format_type == "has_structure") { echo "Inferring the form of each entry in order to create a schema...<BR>"; $sd = new schema_discoverer(); $schema = $sd->create_schema($db_file,$head_tag); $out = fopen("$path/schema.xml","w"); fwrite($out,$schema); fclose($out); echo "Determined the schema.<BR><BR>"; } else if($format_type == "needs_structure") { /* $id_field = strtolower($_POST["id_field"]); $checker = new schema_checker(); echo "Checking for errors in the structure of your database based on the supplied schema...<BR>"; $errors = $checker->check_schema($schema,$db_file,$id_field); if(count($errors) > 0) { echo "One or more entries in your database do not match the schema.<BR>"; echo "Please make the necessary changes to the following entries:<BR>"; foreach($errors as $count=>$error) { echo ($count+1)." $error <BR>"; } } else { echo "No errors found.<BR><BR>"; echo "Converting flat xml to hierarchical xml...<BR>"; $converter = new flat_to_hierarchy_converter(); $converter->produce_xml_with_hierarchy($database,$db_file,$schema, $new_database_name,"$path/schema.xml"); unlink($db_file); $db_file = $new_database_name; echo "Created hierarchical database.<BR><BR>"; } */ } if(count($errors) == 0) { echo "Loading database into MySQL...<BR>"; $mode = 1; $dl = new db_loader($mode,$db_file,$path."/schema.xml",$database); $dl->xml_to_tabledata(); echo "Finished loading database. You are now ready to test!<BR>"; } echo "Fields included in the database:<BR>"; $include = $fields; foreach($strippable_fields as $field) { $include[] = $field."_s"; } sort($include); foreach($include as $field) { echo "$field <BR>"; } } ?>