Code

Added ppd remove ability to ppd selection dialog ..
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 30 Nov 2006 05:51:21 +0000 (05:51 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 30 Nov 2006 05:51:21 +0000 (05:51 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5252 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_printerPPDSelectionDialog.inc
plugins/admin/systems/remove_ppd.tpl [new file with mode: 0644]

index 335c947b56f4d31e81322bb4f79b9b10e6cb28fe..6bd420e690809e7f1e2c21c73a996bc2b9a81543 100644 (file)
@@ -14,7 +14,7 @@ class printerPPDSelectionDialog extends plugin
 
   var $list                 =array();
   var $header               =array();
-
+  var $current_del_id       = "";
   var $Vendor               = "";
 
   function printerPPDSelectionDialog ($config, $dn= NULL,$list=false,$headers=false,$ppd=false)
@@ -54,13 +54,66 @@ class printerPPDSelectionDialog extends plugin
     
     $regex = str_replace("**","*",$regex);
     $_SESSION['printerPPDSelectionDialog']['regex'] = $regex;
-  
+
+    /* Delete requested, check if everything is ok and display confirmation dialog */
+    if(isset($_GET['act']) && $_GET['act'] == "del"){
+
+      /* Get id and check if id is valid */
+      $id_to_del = base64_decode($_GET['id']);
+      $found = "";
+      foreach($this->list[$this->Vendor] as $key => $data){
+        if($data['link'] == $id_to_del){
+          $found = $key;
+          break;
+        }
+      }
+      if(!empty($found)){
+        $this->current_del_id = $id_to_del;
+
+        $smarty->assign("warning", sprintf(_("You're about to delete the ppd file '%s' at '%s'."), $found,$id_to_del));
+        return($smarty->fetch(get_template_path('remove_ppd.tpl', TRUE)));
+
+      }else{
+        print_red(sprintf(_("Could not found specified ppd file '%s'."),$id_to_del));
+      }
+    }
+
+    /* Deletion confirmed */
+    if(isset($_POST['delete_ppd_confirm']) && !empty($this->current_del_id)){
+
+      /* check if file is removeable */
+      if(is_writeable($this->current_del_id)){
+        $is_ok = @unlink($this->current_del_id);
+
+        /* Update ppd list */
+        if($is_ok){
+          foreach($this->list as $vendor => $ppds){
+            foreach($ppds as $ppd => $data){
+              if($data['link'] == $this->current_del_id){
+                unset($this->list[$vendor][$ppd]);
+              }
+            }
+          }
+        }
+      }else{
+        $is_ok = false;
+      }
+
+      if(!$is_ok){
+        print_red(_("Something went wrong while trying to remove the ppd file from server, possibly we have no write access."));
+      }
+    }
+
+
     /** Added **/
     $list = array();
     foreach($this->list as $cat => $ppds){
       foreach($ppds as $ppd){
         if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
-          $list[$ppd['link']] = $ppd;
+          if(is_readable($ppd['link'])){
+            $list[$ppd['link']] = $ppd;
+          }
         }
       }
     }
@@ -81,7 +134,7 @@ class printerPPDSelectionDialog extends plugin
     
     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
     $uselink  = "<a href='?plug=".$_GET['plug']."&amp;act=use&amp;id=%s'>%s</a>";
-    
+    $dellink  = "<a href='?plug=".$_GET['plug']."&amp;act=del&amp;id=%s'><img src='images/edittrash.png' alt='"._("delete")."' border=0></a>"; 
 
     if(empty($this->Vendor)){
       foreach($this-> header as $key => $entry){
@@ -95,8 +148,17 @@ class printerPPDSelectionDialog extends plugin
             ));
       foreach($list as $key => $ppd){
         if(preg_match("/^".$this->Vendor."/",$ppd['ppd'])){
+
+          if(is_writeable($ppd['link'])){
+            $del_str = sprintf($dellink,base64_encode($key));
+          }else{
+            $del_str = "";
+          }
+
           $div ->AddEntry (array(
-                array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd']),"attach"=>"style='border-right:0px;'")
+                                  array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd'])),
+                                  array("string"=>$del_str,"attach"=>"style='border-right:0px;'")
+
                 ));
         }
       }
diff --git a/plugins/admin/systems/remove_ppd.tpl b/plugins/admin/systems/remove_ppd.tpl
new file mode 100644 (file)
index 0000000..6d28ba9
--- /dev/null
@@ -0,0 +1,15 @@
+<div style="font-size:18px;">
+<img alt="" src="images/button_cancel.png" align=top>&nbsp;{t}Warning{/t}
+</div>
+<p>
+ {$warning}
+</p>
+
+<p>
+ {t}The ppd file will be removed from the server and can not be restored.{/t}
+</p>
+<p class="plugbottom">
+  <input type=submit name="delete_ppd_confirm" value="{t}Delete{/t}">
+  &nbsp;
+  <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+</p>