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/my_dictionary.php4
<? include_once("db_loader.php4"); include_once("schema_loader.php4"); include_once("mysql_to_xml.php4"); class my_dictionary { var $DELETE_REFS = 0; var $ADD_REFS = 1; function update_refset($username,$refs,$update_type) { $vars = array("database"=>"mydict","phrases_and_fields_0"=>"username","reg_exps_0"=>"field REGEXP '^&$'","string_0"=>$username,"sort_order"=>"alpha"); $converter = new mysql_to_xml($vars); $ids = $converter->query_database(); if(count($ids) == 1) { $id = $ids[0]; $group = $converter->load_resultset_into_group($id); } else { $sl = new schema_loader(); $group = $sl->create_group_structure("../mydict/schema.xml",""); $group->add_value("username",$username); $group->template .= "username "; } if($update_type == $this->DELETE_REFS) { $group->group_vals["refset"] = array(); $group->template = "username "; } foreach($refs as $ref) { $g = $group->groups["refset"]; $g->add_value("ref",$ref); $group->group_vals["refset"][] = $g; $group->template .= "refset ref /refset "; unset($g); } $xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<database>\n"; $template = explode(" ",trim($group->template)); $xml .= $group->to_xml_3($template,true); $xml .= "</database>"; $out = fopen("temp.xml","w"); fwrite($out,$xml); fclose($out); $db_loader = new db_loader(0,"temp.xml","../mydict/schema.xml","mydict"); $db_loader->xml_to_tabledata(); //unlink("temp.xml"); } function view_refset($username,$project_database,$stylesheet) { $vars = array("database"=>"mydict","phrases_and_fields_0"=>"username","reg_exps_0"=>"field REGEXP '^&$'","string_0"=>$username,"sort_order"=>"alpha"); $converter = new mysql_to_xml($vars); $ids = $converter->query_database(); if(count($ids) == 1) { $id = $ids[0]; $group = $converter->load_resultset_into_group($id); $refs = array(); foreach($group->group_vals["refset"] as $g) { $ref = $g->field_vals["ref"][0]; $refs[] = $g->field_vals["ref"][0]; unset($g); } $vars = array("database"=>$project_database); $vars["num_conditions"] = count($refs); $vars["sort_order"] = "lxa lxo"; foreach($refs as $i=>$ref) { $string_var = "string_".$i; $vars[$string_var] = $ref; $fields_var = "phrases_and_fields_".$i; $vars[$fields_var] = "ref"; $reg_exp_var = "reg_exps_".$i; $vars[$reg_exp_var] = "field regexp '^&$'"; $connective_var = "connectives_".$i; $vars[$connective_var] = "OR"; } $converter = new mysql_to_xml($vars); $ids = $converter->query_database(); $page = 1; $_SESSION["main_ids"] = $ids; $_SESSION["prev_page"] = $page; $_SESSION["prev_stylesheet"] = $stylesheet; $xml = $converter->convert_resultset_to_xml($ids, $page, $stylesheet); header("Content-Type: application/xml"); echo $xml; } else { echo "user $username doesn't exist <BR>"; } return $refs; } function delete_refs($username,$refs, $refs_to_delete) { foreach($refs as $ref) { $query = "DELETE FROM mydict_refset WHERE ref_0='$ref'"; mysql_query($query); } foreach($refs_to_delete as $ref) { $index = array_search($ref, $refs); unset($refs[$index]); } $this->update_refset($username,$refs,$this->DELETE_REFS); } } session_start(); $project_database = $_SESSION["project_database"]; $username = $_SESSION["username"]; $form_vars = array_merge($_POST,$_GET); $function = strtolower($form_vars["function"]); $md = new my_dictionary(); if($username != "") { if($function == "view_refset") { $stylesheet = $form_vars["stylesheet"]; $refs = $md->view_refset($username,$project_database,$stylesheet); $_SESSION["refs"] = $refs; } else if($function == "delete_refs") { $refs_to_delete = $_POST["refs_to_delete"]; $refs = $_SESSION["refs"]; $stylesheet = $_SESSION["prev_stylesheet"]; $md->delete_refs($username,$refs,$refs_to_delete); echo "You have successfully deleted entries from My Dictionary.<BR>"; echo "Click <a href=\"../lex/mydictionary_query.html\">here</a> to return to dictionary page.<BR>"; echo "Click <a href=\"../php4/my_dictionary.php4?function=view_refset&stylesheet=$prev_stylesheet\">here</a> to continue viewing My Dictionary.<BR>"; } else if($function == "add_refs") { $refs = $_POST["refs"]; $md->update_refset($username,$refs,$md->ADD_REFS); $converter = new mysql_to_xml(array("database"=>$project_database)); $main_ids = $_SESSION["main_ids"]; $page = $_SESSION["prev_page"]; $stylesheet = $_SESSION["prev_stylesheet"]; $xml = $converter->convert_resultset_to_xml($main_ids, $page, $stylesheet); header("Content-Type: application/xml"); echo $xml; } } else { echo "username is empty<BR>"; } $_SESSION["project_database"] = $project_database; ?>