Tryag File Manager
Home
-
Turbo Force
Current Path :
/
home
/
cluster1
/
data
/
bu01
/
1121861
/
html
/
jlex
/
php4
/
Upload File :
New :
File
Dir
/home/cluster1/data/bu01/1121861/html/jlex/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"; include_once "project_defaults.php4"; set_time_limit(0); //error_reporting(0); session_start(); $function = strtolower($_POST["function"]); if($function == "get_fields") { $project = strtolower($_POST["project"]); $db_file = "../project_xml_files/".$_POST["db_file"]; $head_tag = strtolower($_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("../$project/schema.xml")) { $sl = new schema_loader(); $group = $sl->create_group_structure("../$project/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='../nahuatl/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") { $vars = $_SESSION["vars"]; $sort_fields = strtolower($vars["sort_fields"]); $head_tag = strtolower($vars["head_tag"]); $project = strtolower($vars["project"]); $symbols = $vars["symbols"]; $first_chars = $vars["first_chars"]; $fields = $vars["fields"]; $strippable_fields = $vars["strippable_fields"]; $db_file = "../project_xml_files/".$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 == "") && ($this->sort_fields == ""))) { $new_name = $db_file.".temp"; $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 = "../$project"; 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($project,$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(); $dl->xml_to_db_bulk($project,$path."/schema.xml",$db_file,$mode); if(ereg("temp",$db_file)) { unlink($db_file); } echo "Finished loading database. You are now ready to test!<BR>"; } echo "Click <b><a href='../$project/defaults.xml'>HERE</a></b> to search your project.<BR><BR>"; echo "Fields included in the database:<BR>"; $sl = new schema_loader(); $group = $sl->create_group_structure("../$project/schema.xml",""); $fields = $group->get_field_names(); foreach($fields as $field) { echo "$field <BR>"; } $pd = new project_defaults(); if(file_exists("../$project/defaults.xml")) { $defaults_file = "../$project/defaults.xml"; } else { $defaults_file = "../project_default_files/defaults.xml"; } $defaults = $pd->get_project_defaults($defaults_file); $defaults["project"] = $project; if($sort_fields != "") { $defaults["sort_order"] = "alpha"; } else { $defaults["sort_order"] = ""; } $xml = "<?xml version='1.0' encoding='iso-8859-1'?>\n"; $xml .= "<?xml-stylesheet href='search_form.xsl' type='text/xsl'?>\n"; $xml .= "<defaults>\n"; foreach($defaults as $tag=>$value) { $xml .= "<$tag>$value</$tag>\n"; } $xml .= "</defaults>"; $out = fopen("../$project/defaults.xml","w"); fwrite($out,$xml); fclose($out); if(!file_exists("../$project/connectives.xml")) { copy("../project_default_files/connectives.xml","../$project/connectives.xml"); } if(!file_exists("../$project/reg_exps.xml")) { copy("../project_default_files/reg_exps.xml","../$project/reg_exps.xml"); } if(!file_exists("../$project/phrases_and_fields.xml")) { $xml = "<PHRASES_AND_FIELDS>\n"; foreach($fields as $field) { $xml .= "<SET>\n"; $xml .= "<ENGLISH>$field</ENGLISH>\n"; $xml .= "<VALUE>$field</VALUE>\n"; $xml .= "</SET>\n"; } $xml .= "</PHRASES_AND_FIELDS>\n"; $out = fopen("../$project/phrases_and_fields.xml","w"); fwrite($out,$xml); fclose($out); } if(!file_exists("../$project/search_form.xsl")){ copy("../project_default_files/search_form.xsl","../$project/search_form.xsl"); } } ?>