all in the datastore.
[glcas.git] / lib / plugins / datastore.php
index ccaca5c..1b2ff4f 100644 (file)
@@ -4,17 +4,56 @@ global $BASE_URLS, $MENU_ITEMS, $GLOBAL_BASE_URL;
 $BASE_URLS["ds"]["base"] = "ds"; // ap for apt-proxy
 $BASE_URLS["ds"]["function"] = "ds_contentUrls"; // the page builder function for us
 $MENU_ITEMS["ds"]["title"] = "DataStores";
-$MENU_ITEMS["ds"]["link"] = "$GLOBAL_BASE_URL/ds/control";
+$MENU_ITEMS["ds"]["link"] = "/ds/control";
 
 
 function ds_contentPane()
 {
-       echo "i am a ds content pane<br>";
+       global $URL_COMPONENTS;
+       if(isset($URL_COMPONENTS[1])) {
+               switch($URL_COMPONENTS[1]) {
+                       case "browse":
+                               $dsbr = $URL_COMPONENTS[2];
+                               echo "<h3>Browsing, $dsbr</h3><br>";
+                               break;
+                       case "createds":
+                               ds_createDS($_REQUEST["dsname"], $_REQUEST["dsloc"]);
+                               echo "DS Created, <a href=\"".urlCreate("/ds/control")."\">return</a>";
+                               break;
+                       case "control":
+                       default:
+                               ds_controlPane();
+                               // go thru the db and list the components
+               }
+       }
+}
+
+function ds_controlPane()
+{
+       echo "<table>";
+       echo "<tr><td>DataStore Name</td><td>DataStore Path</td><td>Size</td><td>Usage</td><td>Control</td></tr>";
+       
+       echo "</table>";
+       echo "<form method=\"post\" action=\"".urlCreate("/ds/createds")."\">";
+       echo "DataStore Name: <input type=\"text\" name=\"dsname\">";
+       echo "DataStore Location: <input type=\"text\" name=\"dsloc\">";
+       echo "<input type=\"submit\" name=\"create\" value=\"create\">";
+       echo "</form>";
+       
 }
 
 function ds_leftMenu()
 {
-       echo "i am a ds leftmenu";
+       global $GLOBAL_BASE_URL;
+       echo "<b>Browse</b><br>";
+       $dss = ds_listDS();
+       echo "<pre>";
+       //print_r($dss);
+       echo "</pre>";
+       foreach ($dss as $dsl) {
+               $dsname = $dsl["dsname"];
+               echo "<a href=\"".urlCreate("/ds/browse/$dsname")."\">$dsname</a><br>";
+       }
 }
 
 function ds_contentUrls()
@@ -28,11 +67,64 @@ function ds_contentUrls()
 
 function ds_createDS($ds_name, $store_location)
 {
+       db_createTable("datastores", "dsname", "dslocation");
+       db_createTable("datastores_files", "dsname", "fileowner", "filename", "dsfname");
+       
+       $data = db_selectData("datastores", "dsname", "$ds_name");
+       if(isset($data[0]["dsname"])) return false;
        
+       db_insertData("datastores", "$ds_name", "$store_location");
 }
 
-function ds_fileds($ds_name, $file_id, $file_name)
+function ds_listDS()
+{
+       return db_selectData("datastores");
+}
+
+function ds_deleteFile($ds_name, $file_name, $file_tag)
+{
+       $dlk = db_selectData("datastores_files", "filename", $file_name);
+       $afname = "";
+       foreach($dlk as $kmm) {
+               if($kmm["fileowner"] == $file_tag) {
+                       // we got ya
+                       $afname = $kmm["dsfname"];
+                       if(file_exists($afname)) unlink($afname);
+                       //echo "name was: $afname\n";
+               }
+       }
+       //echo "now delete name was: $afname\n";
+       if($afname != "") db_deleteData("datastores_files", "dsfname", $afname);
+}
+
+// returns a file name to the location a file can be created
+function ds_fileds($ds_name, $file_name, $file_tag)
+{
+
+       $data = db_selectData("datastores", "dsname", "$ds_name");
+       
+       $dtime = time();
+       $made_file_name = "$dtime-".md5($file_name)."-".basename($file_name);
+       
+       $act_fname = $data[0]["dslocation"]."/".basename($made_file_name);
+       
+       db_insertData("datastores_files", "$ds_name", "$file_tag", "$file_name", "$act_fname");
+       
+       return $act_fname;
+}
+
+function ds_getFileList($ds_name, $file_tag)
+{
+       $list = db_selectData("datastores_files", "fileowner", "$file_tag");
+       
+       return $list;
+}
+
+
+function ds_deleteDS($ds_name)
 {
+       db_deleteData("datastores", "dsname", "$ds_name");
+       db_deleteData("datastores_files", "dsname", $ds_name);
 }
 
 function ds_downloadAndStore($ds_name, $file_id, $file_name, $file_url)