From bd94721918f18baab3190c033b1528162c7e5c7f Mon Sep 17 00:00:00 2001
From: markleeds
Date: Fri, 20 Mar 2009 14:03:58 +0000
Subject: [PATCH] import/export
---
interface/forms/CAMOS/admin.php | 151 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 151 insertions(+)
create mode 100644 interface/forms/CAMOS/admin.php
diff --git a/interface/forms/CAMOS/admin.php b/interface/forms/CAMOS/admin.php
new file mode 100644
index 000000000..3141361b4
--- /dev/null
+++ b/interface/forms/CAMOS/admin.php
@@ -0,0 +1,151 @@
+
+failed!";}
+ else {
+ $query1 = "select id, category from form_CAMOS_category";
+ $statement1 = sqlStatement($query1);
+ while ($result1 = sqlFetchArray($statement1)) {
+ $tmp = $result1['category'];
+ $tmp = "$tmp"."\n";
+ fwrite($temp, $tmp);
+ $query2 = "select id,subcategory from form_CAMOS_subcategory where category_id=".$result1['id'];
+ $statement2 = sqlStatement($query2);
+ while ($result2 = sqlFetchArray($statement2)) {
+ $tmp = $result2['subcategory'];
+ $tmp = "$tmp"."\n";
+ fwrite($temp, $tmp);
+ $query3 = "select item, content from form_CAMOS_item where subcategory_id=".$result2['id'];
+ $statement3 = sqlStatement($query3);
+ while ($result3 = sqlFetchArray($statement3)) {
+ $tmp = $result3['item'];
+ $tmp = "- $tmp
"."\n";
+ fwrite($temp, $tmp);
+ $tmp = preg_replace(array("/\n/","/\r/"),array("\\\\n","\\\\r"),$result3['content']);
+ $tmp = "$tmp"."\n";
+ fwrite($temp, $tmp);
+ }
+ }
+ }
+ rewind($temp);
+ header("Pragma: public");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header("Content-Type: text/plain");
+ header("Content-Disposition: attachment; filename=\"CAMOS_export.txt\"");
+
+ fpassthru($temp);
+ fclose($temp);
+ }
+}
+if ($_POST['import']) {
+?>
+tmp filename: ".$file['tmp_name']."
";
+ }
+ $handle = @fopen($fname,"r");
+ if ($handle === false) {
+ echo "Error opening uploaded file for reading.
";
+ } else {
+ $category = '';
+ $category_id = 0;
+ $subcategory = '';
+ $subcategory_id = 0;
+ $item = '';
+ $item_id = 0;
+ $content = '';
+ while (!feof($handle)) {
+ $buffer = fgets($handle);
+ if (preg_match('/(.*?)<\/category>/',$buffer,$matches)) {
+
+ $category = addslashes(trim($matches[1])); //trim in case someone edited by hand and added spaces
+ $statement = sqlStatement("select id from form_CAMOS_category where category like \"$category\"");
+ if ($result = sqlFetchArray($statement)) {
+ $category_id = $result['id'];
+ } else {
+ $query = "INSERT INTO form_CAMOS_category (user, category) ".
+ "values ('".$_SESSION['authUser']."', \"$category\")";
+ sqlInsert($query);
+ $statement = sqlStatement("select id from form_CAMOS_category where category like \"$category\"");
+ if ($result = sqlFetchArray($statement)) {
+ $category_id = $result['id'];
+ }
+ }
+ }
+ if (preg_match('/(.*?)<\/subcategory>/',$buffer,$matches)) {
+
+ $subcategory = addslashes(trim($matches[1]));
+ $statement = sqlStatement("select id from form_CAMOS_subcategory where subcategory " .
+ "like \"$subcategory\" and category_id = $category_id");
+ if ($result = sqlFetchArray($statement)) {
+ $subcategory_id = $result['id'];
+ } else {
+ $query = "INSERT INTO form_CAMOS_subcategory (user, subcategory, category_id) ".
+ "values ('".$_SESSION['authUser']."', \"$subcategory\", $category_id)";
+ sqlInsert($query);
+ $statement = sqlStatement("select id from form_CAMOS_subcategory where subcategory " .
+ "like \"$subcategory\" and category_id = $category_id");
+ if ($result = sqlFetchArray($statement)) {
+ $subcategory_id = $result['id'];
+ }
+ }
+ }
+ if ((preg_match('/<(item)>(.*?)<\/item>/',$buffer,$matches)) ||
+ (preg_match('/<(content)>(.*?)<\/content>/s',$buffer,$matches))) {
+
+ $mode = $matches[1];
+ $value = addslashes(trim($matches[2]));
+ if ($mode == 'item') {
+ $statement = sqlStatement("select id from form_CAMOS_item where item like \"$value\" " .
+ "and subcategory_id = $subcategory_id");
+ if ($result = sqlFetchArray($statement)) {
+ $item_id = $result['id'];
+ } else {
+ $query = "INSERT INTO form_CAMOS_item (user, item, subcategory_id) ".
+ "values ('".$_SESSION['authUser']."', \"$value\", $subcategory_id)";
+ sqlInsert($query);
+ $statement = sqlStatement("select id from form_CAMOS_item where item like \"$value\" " .
+ "and subcategory_id = $subcategory_id");
+ if ($result = sqlFetchArray($statement)) {
+ $item_id = $result['id'];
+ }
+ }
+ }
+ elseif ($mode == 'content') {
+ $statement = sqlStatement("select content from form_CAMOS_item where id = ".$item_id);
+ if ($result = sqlFetchArray($statement)) {
+ //$content = "/*old*/\n\n".$result['content']."\n\n/*new*/\n\n$value";
+ $content = $value;
+ } else {
+ $content = $value;
+ }
+ $query = "UPDATE form_CAMOS_item set content = \"$content\" where id = ".$item_id;
+ sqlInsert($query);
+ }
+ }
+ }
+ fclose($handle);
+ }
+}
+?>
+
+
+
+admin
+
+
+
+
+
+
--
2.11.4.GIT