hey, we have a working fooker...
[php-bacula-disk-changer.git] / bin / pbdc-bacula.php
index 5a36526..b136d05 100644 (file)
@@ -114,25 +114,17 @@ function loaded_tape()
        }
        
        $ret = false;
-       $i=1;
+       $i=-1;
+       
+       $sql = "select slot_no from slots where tape_name=='$rl'";
+       $res = $db->query($sql);
+       
        foreach($res as $row) {
-               //echo "Listing tapes for disk ".$row["disk_id"].", ".$row["disk_name"]."\n";
-               //echo "dir: $amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/\n";
-               //exit(0);
-               $dh = opendir("$amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/");
-               while(($file = readdir($dh)) !== false) {
-                       if(ereg("d[0-9]+_vol[0-9]+", $file)!=false) {
-                               if($rl == $file) {
-                                       echo "$i\n";
-                                       exit(0);
-                               }
-                               $i++;
-                       } else {
-                               //echo "didnt match: $file\n";
-                       }
-                       //exit(0);
-               }
-               closedir($dh);
+               $i = $row[0];
+       }
+       if($i != -1) {
+               echo "$i\n";
+               return;
        }
        
        echo "0\n";
@@ -164,9 +156,9 @@ function list_tapes()
                }
                $tn = "$amloc/".$dn."/pbdc/".$argv[1]."/tapes/$tapename";
                if(file_exists($tn)) {
-                       echo "slot $sn: $tapename\n";
+                       echo "$sn:$tapename\n";
                } else {
-                       echo "slot $sn:\n";
+                       echo "$sn:\n";
                }
        }
        
@@ -186,7 +178,8 @@ function num_slots()
                $mslot = $row[0];
        }
        
-       return $mslot;
+       echo "$mslot\n";
+       return;
        
 //     $amloc = conf_getVal($changer, "automountdir");