Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
code for contact upload script
authorathreyab <athreyab@localhost>
Thu, 21 Feb 2013 05:12:18 +0000 (05:12 +0000)
committerathreyab <athreyab@localhost>
Thu, 21 Feb 2013 05:12:18 +0000 (05:12 +0000)
svn path=/; revision=430

Personnel/athreyab/image_annotation_db/ia_upload/contact_process.php [new file with mode: 0755]
Personnel/athreyab/image_annotation_db/ia_upload/data.html [new file with mode: 0755]
Personnel/athreyab/image_annotation_db/ia_upload/index.html [new file with mode: 0755]

diff --git a/Personnel/athreyab/image_annotation_db/ia_upload/contact_process.php b/Personnel/athreyab/image_annotation_db/ia_upload/contact_process.php
new file mode 100755 (executable)
index 0000000..64d6287
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+
+  //db config values
+  $dbHost =  "localhost";
+  $dbUser = "root";
+  $dbPwd = "root";
+  $connection = mysql_connect($dbHost,$dbUser,$dbPwd);
+  mysql_select_db("image_annotation"); 
+  
+  function getRowFromDB($query,$value){
+               $rsrcResult = mysql_query($query);
+               if (!$rsrcResult) {
+                       echo "DB Error while trying to retrieve $value\n MySQL Error: ".mysql_error();
+      exit();
+               }
+                       $row = mysql_fetch_row($rsrcResult);
+                       return $row;
+       }
+  
+  function save_image_source_information($contact){
+      $contributor_name = $contact['contributor_name'];
+      $source_name = $contact['source_name'];
+      $url = $contact['url'];
+      $contact_email = $contact['contact_email'];
+      $id_from_db = get_image_source_id($contributor_name,$source_name);
+      if($id_from_db == -1){
+        $query = "INSERT INTO image_source(source_name,url,contact_email,contributor_name) VALUES('$source_name','$url','$contact_email','$contributor_name')";
+        $rsrcResult = mysql_query($query);
+        if (!$rsrcResult) {
+          echo "DB Error while trying to add new image source information\n";
+          echo 'MySQL Error: ' . mysql_error();
+          exit();
+        }
+        $id_from_db = get_image_source_id($contributor_name,$source_name);
+      }
+      return $id_from_db;
+    }
+    
+    function get_image_source_id($contributor_name,$source_name){
+      $query = "select image_source_id from  image_source where contributor_name='$contributor_name' and source_name='$source_name'";
+      $row = getRowFromDB($query,"image source id");
+      if(count($row) == 0 || (count($row) > 0 && $row[0] == ''))
+        return -1;        
+      return $row[0];
+    }
+      
+    function get_image_source_version_id($image_source_id,$source_version){
+      $query = "select image_source_version_id from  image_source_version where image_source_id='$image_source_id' and source_version='$source_version'";
+      $row = getRowFromDB($query,"image source version id");
+      if(count($row) == 0 || (count($row) > 0 && $row[0] == ''))
+        return -1;
+      return $row[0];
+    }
+      
+    function save_image_source_version_information($image_source_id,$contact){
+      $source_version = $contact['source_version'];
+      $publication_id = $contact['publication_id'];
+      $contribution_date = $contact['contribution_date'];
+      $mysqldate = date( 'Y-m-d H:i:s', $contribution_date );
+      $contribution_date = strtotime( $mysqldate );
+
+      $id_from_db = get_image_source_version_id($image_source_id,$source_version);
+      if($id_from_db == -1){
+        $query = "INSERT INTO image_source_version(image_source_id,source_version,contribution_date,publication_id) VALUES('$image_source_id','$source_version','$contribution_date','$publication_id')";
+        $rsrcResult = mysql_query($query);
+        if (!$rsrcResult) {
+          echo "DB Error while trying to add new image source version information\n";
+          echo 'MySQL Error: ' . mysql_error();
+          exit();
+        }
+        $id_from_db = get_image_source_version_id($image_source_id,$source_version);
+      }
+      return $id_from_db;
+    }
+    
+  $file = $_FILES['file']['tmp_name'];
+  $file_handle = fopen($file, "r");
+  $contact = array();
+  while (!feof($file_handle)) {
+    $line = fgets($file_handle);
+    $s = explode("\t",$line);
+    if($s[0] != "")
+      $contact[$s[0]] = $s[1];
+  }  
+  fclose($file_handle);
+  
+  if(count($contact) < 4 || $contact['source_name'] == '' || $contact['contributor_name'] == '' || $contact['contact_email'] == '' || $contact['contribution_date'] == ''){
+    echo "Required information is missing. ";
+  }  
+  else{
+    $image_source_id = save_image_source_information($contact);
+    $image_source_version_id = save_image_source_version_information($image_source_id,$contact);
+    
+    if($image_source_id != -1 && $image_source_version_id != -1){
+      echo "information saved successfully<br/>";
+      echo "<a href='data.html'>Click here to upload annotated image data file</a>";
+    }
+    else{
+      echo "Couldn't save information";        
+      exit();
+    }
+  }
+  
+?>
diff --git a/Personnel/athreyab/image_annotation_db/ia_upload/data.html b/Personnel/athreyab/image_annotation_db/ia_upload/data.html
new file mode 100755 (executable)
index 0000000..8972814
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+<head>
+<title>Tool for uploading image annotation information</title>
+</head>
+<body>
+<center><h1>Tool for uploading image annotation information</h1></center>
+<h2>Step 2</h2>
+<p>Please upload the image annotation information file below</p>
+<br/><br/><br/>
+<form action="data_process.php" method="post" enctype="multipart/form-data">
+  <label for="file">Contact information file:</label>
+  <input type="file" name="file" id="file" /> 
+  <br />
+  <input type="submit" name="submit" value="Submit" />
+</form>
+
+</body>
+</html>
diff --git a/Personnel/athreyab/image_annotation_db/ia_upload/index.html b/Personnel/athreyab/image_annotation_db/ia_upload/index.html
new file mode 100755 (executable)
index 0000000..1f3ded2
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+<head>
+<title>Tool for uploading image annotation information</title>
+</head>
+<body>
+<center><h1>Tool for uploading image annotation information</h1></center>
+<h2>Step 1</h2>
+<p>Please upload the contact information file below</p>
+<br/><br/><br/>
+<form action="contact_process.php" method="post" enctype="multipart/form-data">
+  <label for="file">Contact information file:</label>
+  <input type="file" name="file" id="file" /> 
+  <br />
+  <input type="submit" name="submit" value="Submit" />
+</form>
+
+</body>
+</html>