}
echo "Creating database\n";
- $r = readline("Directory where automount occurs [/changer/]:");
- $r = readline("Number of drives [1]:");
- $r = readline("Size of tapes [20] (in gb):");
+ $ra = readline("Directory where automount occurs [/changer/]:");
+ $rb = readline("Number of drives [1]:");
+ $rc = readline("Size of tapes [20] (in gb):");
+
+ if($ra == "") $ra = "/changer/";
+ if($rb == "") $rb = 1;
+ if($rc == "") $rc = 20;
+
+ db_getDB($changer_name);
}
function add_disk()
}
// now we try and init the disk
+ // we have to get automount directory config
+ //$k = mkdir();
}
?>
\ No newline at end of file
-# some sql goes here
+CREATE TABLE "disk_list" (
+ "disk_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
+ "disk_name" TEXT NOT NULL
+);
+CREATE TABLE sqlite_sequence(name,seq);
+CREATE TABLE "config" (
+ "config_name" TEXT NOT NULL,
+ "config_value" TEXT NOT NULL
+);
<?php
+
+function db_getDB($changer_name)
+{
+ global $BASE_DATA, $BASE_LIB, $BACULA_USER;
+
+ try {
+ $dbobject = new PDO("sqlite:$BASE_DATA/$changer_name"."db");
+ } catch(PDOException $exep) {
+ echo "<font color='red'>Cannot open sqlitedb, ".$exep->getMessage()."</font><br>";
+ return;
+ }
+
+
+ db_createDB($dbobject);
+
+ return $dbobject;
+}
+
+function db_createDB($dbobject)
+{
+
+ if($dbobject->query("select * from disk_list")) {
+ //error_log("table exists?");
+ } else {
+ //error_log("table not exists?");
+ $dbobject->query('CREATE TABLE "disk_list" ("disk_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"disk_name" TEXT NOT NULL);');
+ $dbobject->query('CREATE TABLE sqlite_sequence(name,seq)');
+ $dbobject->query('CREATE TABLE "config" ("config_name" TEXT NOT NULL,"config_value" TEXT NOT NULL)');
+
+ // TODO create action group here
+
+ }
+}
+
+function conf_getVal($name)
+{
+ $db = db_getDB();
+
+ $sql = "select conf_val from conf where conf_name=='$name'";
+ error_log("from getval: ".$sql);
+
+ $res = $db->query($sql);
+
+ if(!$res) return false;
+
+ $val = false;
+
+ foreach($res as $row) {
+ $val = $row["conf_val"];
+ }
+
+ return $val;
+}
+
+function conf_setVal($name, $value)
+{
+ $db = db_getDB();
+
+ $sql = "delete from conf where conf_name=='$name'";
+ $db->query($sql);
+
+ $sql = "insert into conf values ('$name', '$value')";
+ $db->query($sql);
+
+ error_log("from setval: ".$sql);
+}
+?>
\ No newline at end of file