Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Renamed deleteable to shared.
and fixed delete of running images
  • Loading branch information
Phhere committed Apr 4, 2012
1 parent fa8320d commit a8b55d4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
8 changes: 8 additions & 0 deletions classes/Image.class.php
Expand Up @@ -42,4 +42,12 @@ static function getStatus($imageID){
}
return $return;
}

static function isUsed($imageID){
$query = $GLOBALS['pdo']->prepare("SELECT v.status FROM vm_images i JOIN vm v ON v.vmID = i.vmID WHERE i.imageID= :imageID AND v.status = 1");
$query->bindValue(':imageID', $imageID, PDO::PARAM_INT);
$query->execute();

return !($query->rowCount() == 0);
}
}
31 changes: 16 additions & 15 deletions module/images.php
Expand Up @@ -18,11 +18,12 @@ public function post_save_new(){

$do = false;

$query = $GLOBALS['pdo']->prepare("INSERT INTO images (name,path,type,deleteable) VALUES (:name, :path, :type, :deleteable)");
$query = $GLOBALS['pdo']->prepare("INSERT INTO images (name,path,type,shared,owner) VALUES (:name, :path, :type, :shared,:owner)");
$query->bindValue(":name",$_POST['name'],PDO::PARAM_STR);
$query->bindParam(":type",$type,PDO::PARAM_STR);
$query->bindParam(":path",$path,PDO::PARAM_STR);
$query->bindValue(":deleteable",!isset($_POST['deleteable']),PDO::PARAM_INT);
$query->bindValue(":owner",$_SESSION['user']->id,PDO::PARAM_STR);
$query->bindValue(":shared",isset($_POST['shared']),PDO::PARAM_INT);

$type = $_POST['type'];

Expand Down Expand Up @@ -77,11 +78,11 @@ public function post_save_edit(){
}

$do = false;
$query = $GLOBALS['pdo']->prepare("UPDATE images SET name = :name, path = :path, type=:type, deleteable = :deleteable WHERE imageID= :imageID");
$query = $GLOBALS['pdo']->prepare("UPDATE images SET name = :name, path = :path, type=:type, shared = :shared WHERE imageID= :imageID");

$query->bindValue(':name',$_POST['name'],PDO::PARAM_STR);
$query->bindValue(':type',$_POST['type'],PDO::PARAM_STR);
$query->bindValue(':deleteable',!isset($_POST['deleteable']),PDO::PARAM_INT);
$query->bindValue(':shared',isset($_POST['shared']),PDO::PARAM_INT);
$query->bindValue(':imageID',$_POST['image'],PDO::PARAM_INT);
$query->bindParam(':path',$path,PDO::PARAM_STR);

Expand Down Expand Up @@ -199,10 +200,10 @@ public function action_clone(){
if($data['type'] != "usb"){
if(is_dir($data['path']) == false){

$query = $GLOBALS['pdo']->prepare("INSERT INTO images (name,type,deleteable) VALUES (:name, :type, :deleteable)");
$query = $GLOBALS['pdo']->prepare("INSERT INTO images (name,type,shared) VALUES (:name, :type, :shared)");
$query->bindValue(":name",$data['name'],PDO::PARAM_STR);
$query->bindValue(":type",$data['type'],PDO::PARAM_STR);
$query->bindValue(":deleteable",$data['deleteable'],PDO::PARAM_INT);
$query->bindValue(":shared",$data['shared'],PDO::PARAM_INT);
$do = $query->execute();

if($do){
Expand Down Expand Up @@ -290,11 +291,11 @@ public function action_new(){
$create_size = "10G";
}

if(isset($_POST['deleteable'])){
$delete = ' checked="checked"';
if(isset($_POST['shared'])){
$shared = ' checked="checked"';
}
else{
$delete = '';
$shared = '';
}

$usb = '';
Expand All @@ -319,7 +320,7 @@ public function action_new(){
$tmp2->assign('path_create',$path_create);
$tmp2->assign('create_type',$create_type);
$tmp2->assign('create_size',$create_size);
$tmp2->assign('delete',$delete);
$tmp2->assign('shared',$shared);
$tmp2->assign('usb_device',$usb);
return $tmp2->draw('image_new',true);
}
Expand All @@ -344,11 +345,11 @@ public function action_edit(){

$types = str_replace('value="'.$data['type'].'"', 'value="'.$data['type'].'" selected="selected"', $GLOBALS['device_types']);

if(!$data['deleteable']){
$delete = ' checked="checked"';
if(!$data['shared']){
$shared = ' checked="checked"';
}
else{
$delete = '';
$shared = '';
}

$usb = '';
Expand Down Expand Up @@ -385,7 +386,7 @@ public function action_edit(){
$tmp2->assign('class_usb',$style_usb);
$tmp2->assign('class_path',$style_path);
$tmp2->assign('imageID',$data['imageID']);
$tmp2->assign('delete',$delete);
$tmp2->assign('shared',$shared);
return $tmp2->draw('image_edit',true);
}
else{
Expand Down Expand Up @@ -414,7 +415,7 @@ public function action_default(){
if($_SESSION['user']->role['image_edit'] == 1){
$buttons .= '<a href="index.php?site=images&action=edit&image='.$ds['imageID'].'" class="button small center grey"><span class="icon" data-icon="G"></span>Edit</a>';
}
if($ds['deleteable'] && $ds['status'] == QemuMonitor::SHUTDOWN){
if(Image::isUsed($ds['imageID']) == false && ($ds['owner'] == $_SESSION['user']->id || Modul::hasAccess('image_remove'))){
$buttons .= '<a href="index.php?site=images&action=delete&image='.$ds['imageID'].'" class="button small center grey"><span class="icon" data-icon="T"></span>delete</a>';
}
if($ds['status'] == QemuMonitor::SHUTDOWN && $ds['type'] != 'usb'){
Expand Down
5 changes: 2 additions & 3 deletions templates/image_edit.html
Expand Up @@ -24,9 +24,8 @@
<td><input type="text" class="col_12" name="path" value="{$path}" /></td>
</tr>
<tr>
<th>nicht löschbar:</th>
<td><input type="checkbox" name="deleteable" {$delete}/> Wird genutzt für Laufwerke, die vom Server durchgereicht werden, z.b. CD-Rom oder
USB-Sticks</td>
<th>Teilen:</th>
<td><input type="checkbox" name="shared" {$shared}/> Wird genutzt für Laufwerke, die mit mehreren VMs geteilt werden. Zum Beispiel Laufwerke oder USB-Anschlüsse.</td>
</tr>
</table>
<input type="hidden" name="image" value="{$imageID}" /> <input type="submit" class="center" name="save_edit" value="Speichern" />
Expand Down
4 changes: 2 additions & 2 deletions templates/image_new.html
Expand Up @@ -15,8 +15,8 @@
</select></td>
</tr>
<tr>
<th>nicht löschbar:</th>
<td><input type="checkbox" name="deleteable" {$delete}/>Wird genutzt für Laufwerke, die vom Server durchgereicht werden, z.b. CD-Rom oder USB-Sticks</td>
<th>Teilen:</th>
<td><input type="checkbox" name="shared" {$shared}/>Wird genutzt für Laufwerke, die mit mehreren VMs geteilt werden. Zum Beispiel Laufwerke oder USB-Anschlüsse.</td>
</tr>
</table>
<ul class="tabs left">
Expand Down

0 comments on commit a8b55d4

Please sign in to comment.