Code

Refactor parts of the plugin:
[gosa.git] / gosa-plugins / goto / admin / systems / ppd / class_printerPPDSelectionDialog.inc
index ec93f23f9dceb3a9d78b61268d704409e8bd2188..e0dcd1c939cb9c100783fbd70c7abdd3ead78117 100644 (file)
@@ -72,7 +72,7 @@ class printerPPDSelectionDialog extends plugin
         return($smarty->fetch(get_template_path('remove_ppd.tpl', TRUE)));
 
       }else{
-        print_red(sprintf(_("Could not found specified ppd file '%s'."),$id_to_del));
+        msg_dialog::display(_("PPD error"), msgPool::fileDoesNotExist($id_to_del), ERROR_DIALOG);
       }
     }
 
@@ -80,6 +80,7 @@ class printerPPDSelectionDialog extends plugin
     if(isset($_POST['delete_ppd_confirm']) && !empty($this->current_del_id)){
 
       /* check if file is removeable */
+      $is_ok = false;
       if(is_writeable($this->current_del_id)){
         $is_ok = @unlink($this->current_del_id);
 
@@ -93,12 +94,10 @@ class printerPPDSelectionDialog extends plugin
             }
           }
         }
-      }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."));
+        msg_dialog::display(_("PPD error"), msgPool::cannotDeleteFile($this->current_del_id), ERROR_DIALOG);
       }
     }
 
@@ -107,18 +106,22 @@ class printerPPDSelectionDialog extends plugin
     $list = array();
     foreach($this->list as $cat => $ppds){
       foreach($ppds as $ppd){
-        if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
+       $name = $ppd['ppd']['name'];
+        if(preg_match("/^".str_replace("*",".*",$regex)."/i",$name)){
           if(is_readable($ppd['link'])){
             $list[$ppd['link']] = $ppd;
           }
         }
       }
     }
+    
+    /* Sort the list alphabetically */
+    asort($list);
  
     if((isset($_GET['act']))&&($_GET['act']=="open"))  {
       
       if((!empty($_GET['id'])) && (!isset( $this->header[base64_decode($_GET['id'])]))){
-        print_red(sprintf(_("Selected vendor '%s' does not exists in our list of ppds."),base64_decode($_GET['id'])));      
+        msg_dialog::display(_("PPD error"), sprintf(_("Cannot locate vendor '%s' in available PPDs!"), base64_decode($_GET['id'])), ERROR_DIALOG);
         $this->Vendor = ""; 
       }else{
         $this->Vendor = base64_decode($_GET['id']);
@@ -130,16 +133,17 @@ class printerPPDSelectionDialog extends plugin
     $div ->SetSummary(_("Printer ppd selection."));
     
     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>
-                  <img src='images/folder.png' class='center' border=0>&nbsp;%s
+                  <img src='images/lists/folder.png' class='center' border=0>&nbsp;%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>
+                  <img src='images/lists/trash.png' alt='"._("delete")."' border=0>
                  </a>"; 
 
     if(empty($this->Vendor)){
       foreach($this-> header as $key => $entry){
         $div ->AddEntry (array(
+                 
               array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'")
               ));
       }
@@ -148,7 +152,8 @@ class printerPPDSelectionDialog extends plugin
             array("string"=>sprintf($linkopen,"",".. ["._("back")."]"),"attach"=>"style='border-right:0px;'")
             ));
       foreach($list as $key => $ppd){
-        if(preg_match("/^".$this->Vendor."/",$ppd['ppd'])){
+       $name = $ppd['ppd']['name'];
+        if(preg_match("/^".$this->Vendor."/", $name)){
 
           if(is_writeable($ppd['link'])){
             $del_str = sprintf($dellink,base64_encode($key));
@@ -157,7 +162,7 @@ class printerPPDSelectionDialog extends plugin
           }
 
           $div ->AddEntry (array(
-                                  array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd'])),
+                                  array("string"=>sprintf($uselink,base64_encode($key),$name)),
                                   array("string"=>$del_str,"attach"=>"style='border-right:0px;'")
 
                 ));
@@ -166,9 +171,9 @@ class printerPPDSelectionDialog extends plugin
     }
 
     $smarty->assign("List",         $div -> DrawList());
-    $smarty->assign("search_image", get_template_path('images/search.png'));
-    $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
-    $smarty->assign("tree_image",   get_template_path('images/tree.png'));
+    $smarty->assign("search_image", get_template_path('images/lists/search.png'));
+    $smarty->assign("launchimage",  get_template_path('images/lists/action.png'));
+    $smarty->assign("tree_image",   get_template_path('images/lists/search-subtree.png'));
     $smarty->assign("alphabet",     generate_alphabet());
     $smarty->assign("apply",        apply_filter());
     $smarty->assign("regex",        $regex);