Tryag File Manager
Home
-
Turbo Force
Current Path :
/
home
/
cluster1
/
data
/
bu01
/
1121861
/
jlex
/
php5
/
Upload File :
New :
File
Dir
//home/cluster1/data/bu01/1121861/jlex/php5/mydictionary.php5
<? include_once("db_loader.php5"); include_once("schema_loader.php5"); include_once("mysql_to_xml.php5"); include_once("query_object.php5"); include_once("account_manager.php5"); class mydictionary { var $DELETE_REFS = 0; var $ADD_REFS = 1; /********************************************************************************/ function update_refset($username,$refs,$update_type) { $qo = new query_object(); $qo->set_project("mydict"); $qo->add_condition_set("username","field REGEXP '^~$'",$username); $converter = new mysql_to_xml(); $qo = $converter->query_database($qo); $ids = $qo->get_main_ids(); if(count($ids) == 1) { $id = $ids[0]; $group = $converter->load_resultset_into_group($qo,$id); } else { die("Error: User, $username, does not exist in mydictionary database"); } if($update_type == $this->DELETE_REFS) { $group->group_vals["refset"] = array(); $group->template = "username "; } foreach($refs as $ref){ $g = clone $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_by_template($template,true); $xml .= "</database>"; $dl = new db_loader(); $dl->xml_to_db_bulk("mydict","../mydict/schema.xml",$xml,$dl->UPDATE_DATABASE); unset($_SESSION["ref_ids"]); } /********************************************************************************/ function view_refset($username,$project) { $qo = new query_object(); $qo->set_project("mydict"); $qo->add_condition_set("username","field REGEXP '^~$'",$username); $converter = new mysql_to_xml(); $qo = $converter->query_database($qo); $ids = $qo->get_main_ids(); //$qo->print_values(); if(count($ids) == 1) { $id = $ids[0]; $group = $converter->load_resultset_into_group($qo,$id); $refs = array(); if(@array_key_exists("refset",$group->group_vals)) { foreach($group->group_vals["refset"] as $g) { $ref = $g->field_vals["ref"][0]; $refs[] = $g->field_vals["ref"][0]; unset($g); } } } else { $referer = getenv("HTTP_REFERER"); header("Location: $referer"); } $vars = array("project"=>$project); $query_object = new query_object(); $query_object->fill_query_object($vars,""); $query_object->set_max_conditions(count($refs)); foreach($refs as $i=>$ref) { $query_object->add_condition_set("ref","field regexp '^~$'",$ref); $query_object->add_connective("OR"); } $converter = new mysql_to_xml(); $query_object = $converter->query_database($query_object); $query_object = $converter->convert_resultset_to_xml($query_object); $_SESSION["query_object"] = $query_object; $script = $query_object->get_post_processing_script(); $form_vars["template_type"] = "mydictionary_view"; $form_vars["macron_symbol"] = "colon"; //$query_object->print_values(); include("../$project/$script"); return $refs; } /********************************************************************************/ function delete_refs($username,$refs, $refs_to_delete) { $query = "SELECT user_refs_id FROM mydict_user_refs WHERE username_0='$username'"; $query_result = mysql_query($query); $num_rows = mysql_num_rows($query_result); if($num_rows == 1) { $row = mysql_fetch_assoc($query_result); $id = $row["user_refs_id"]; foreach($refs as $ref) { $query = "DELETE FROM mydict_refset WHERE ref_0='$ref' AND user_refs_id=$id"; mysql_query($query); } foreach($refs_to_delete as $ref) { $keys = array_keys($refs,$ref); foreach($keys as $index) { unset($refs[$index]); } } $this->update_refset($username,$refs,$this->DELETE_REFS); } } /********************************************************************************/ function admin_add_refs($usernames,$refs) { foreach($usernames as $username) { $this->update_refset($username,$refs,$this->ADD_REFS); } } /********************************************************************************/ function search_my_dictionary($username,$form_vars) { if(array_key_exists("ref_ids3",$_SESSION)) { $ref_ids = $_SESSION["ref_ids"]; } else { $query = "SELECT user_refs_id FROM mydict_user_refs WHERE username_0='$username'"; $query_result = mysql_query($query); $num_rows = mysql_num_rows($query_result); $ref_ids = array(); if($num_rows == "1") { $row = mysql_fetch_assoc($query_result); $user_refs_id = $row["user_refs_id"]; $query = "SELECT ref_0 FROM mydict_refset WHERE user_refs_id=$user_refs_id"; $query_result = mysql_query($query); $num_rows = mysql_num_rows($query_result); if($num_rows > 0) { $refs = 0; $qo = new query_object(); $qo->set_project("nahuatl"); $qo->set_max_conditions($num_rows); while($row = mysql_fetch_assoc($query_result)) { $ref = $row["ref_0"]; $qo->add_condition_set("ref","field regexp '^~$'",$ref); $qo->add_connective("OR"); } $converter = new mysql_to_xml(); $qo = $converter->query_database($qo); $ref_ids = $qo->get_main_ids(); } } $_SESSION["ref_ids"] = $ref_ids; } if(array_key_exists("query_object",$_SESSION)) { $query_object = $_SESSION["query_object"]; } else { $query_object = new query_object(); } $project = $form_vars["project"]; $defaults_file = "../$project/defaults.xml"; $defaults = array(); if(file_exists($defaults_file)) { $defaults = $query_object->get_project_defaults($defaults_file); } if(array_key_exists("pre_processing_script",$defaults)) { $pre_processing_script = $defaults["pre_processing_script"]; if(file_exists($pre_processing_script)) { include("../$project/$pre_processing_script"); } } $query_object->fill_query_object($form_vars,$defaults); $query_object = $converter->query_database($query_object); $main_ids = $query_object->get_main_ids(); $ids = array_intersect($main_ids,$ref_ids); $main_ids = array(); foreach($ids as $id) { $main_ids[] = $id; } $query_object->set_main_ids($main_ids); $query_object = $converter->convert_resultset_to_xml($query_object); $_SESSION["query_object"] = $query_object; $post_processing_script = $query_object->get_post_processing_script(); if($post_processing_script != "") { include("../$project/$post_processing_script"); //echo $query_object->print_values(); } else { header("Content-Type: application/xml"); echo $query_object->get_xml(); } } /********************************************************************************/ } session_start(); $project = $_SESSION["project"]; $username = $_SESSION["username"]; $form_vars = array_merge($_POST,$_GET); $function = strtolower($form_vars["function"]); $md = new mydictionary(); if($username != "") { if($function == "view_refset") { $refs = $md->view_refset($username,$project); $_SESSION["refs"] = $refs; } else if($function == "delete_refs") { $refs_to_delete = $_POST["refs"]; $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=\"../nahuatl/html_php5/mydictionary_search.html\">here</a> to return to dictionary page.<BR>"; echo "Click <a href=\"../php5/mydictionary.php5?function=view_refset&template_type=mydictionary_view\">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(); $query_object = $_SESSION["query_object"]; $form_vars["template_type"] = "mydictionary_search_result"; $form_vars["macron_symbol"] = "colon"; $script = "../$project/".$query_object->get_post_processing_script(); include($script); } else if($function == "admin_view") { if(array_key_exists("admin",$_SESSION)) { $view_user = $_GET["view_user"]; $_SESSION["username"] = $view_user; $refs = $md->view_refset($view_user,$project); $_SESSION["refs"] = $refs; } else { $referer = getenv("HTTP_REFERER"); header("Location: $referer"); } } else if($function == "share_refs") { if(array_key_exists("admin",$_SESSION)) { $admin = $_SESSION["admin"]; if($admin != "") { $refs = $_POST["refs"]; $_SESSION["refs_to_share"] = $refs; $ma = new account_manager(); $ma->list_accounts("../user/share_words.xsl"); } } else { $referer = getenv("HTTP_REFERER"); header("Location: $referer"); } } else if($function == "admin_add_refs") { if(array_key_exists("admin",$_SESSION)) { $admin = $_SESSION["admin"]; if($admin != "") { $usernames = ""; $refs = ""; if(array_key_exists("usernames",$_POST)) { $usernames = $_POST["usernames"]; } if(array_key_exists("refs",$_SESSION)) { $refs = $_SESSION["refs_to_share"]; } if(($usernames == "") || ($refs == "")) { $referer = getenv("HTTP_REFERER"); header("Location: $referer"); } else { $md->admin_add_refs($usernames,$refs); $ma = new account_manager(); $ma->list_accounts("../nahuatl/share_words.xsl"); } } } } else if($function == "search_mydictionary") { $username = $_SESSION["username"]; $form_vars = array_merge($_POST, $_GET); $md->search_my_dictionary($username,$form_vars); } } else { echo "No user currently logged in.<BR>"; } ?>