Code

Renamed add/remove buttons
[gosa.git] / plugins / admin / systems / class_glpiPrinterAccount.inc
index af76ba9ccc21e5abeb951b3b0c14608fc3f21e51..59da4baf45669e3bba068a8ff830f3f5ebe79627 100644 (file)
@@ -138,11 +138,11 @@ class glpiPrinterAccount extends plugin
     /*  Assign smarty defaults 
         To avoid undefined indexes, if there is an error with the glpi db
      */ 
-    foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers","Attachments","AttachmentKeys") as $attr){
+    foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers","Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
       $smarty->assign($attr,array());
       $smarty->assign($attr."ACL"," disabled ");
     }
-    foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb") as $attr){
+    foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb","AttachmentsDiv") as $attr){
       $smarty->assign($attr,"");
       $smarty->assign($attr."ACL"," disabled ");
     }
@@ -224,19 +224,52 @@ class glpiPrinterAccount extends plugin
     /* This appends a new printer to our sytem types
      */
     if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
-      $this->handle->addPrinterType($_POST['type_string']);  
+    
+      $tmp = $this->handle->getPrinterTypes();
+      $allok = true;
+      foreach($tmp as $id => $name){
+        if(trim($name) == trim($_POST['type_string'])){
+          $allok = false;
+        }
+      }
+      if($allok){
+        $this->handle->addPrinterType($_POST['type_string']);  
+      }else{
+        print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['type_string']));
+      }
     }
 
     /* Remove selected type from our printer types list
      */
     if((isset($_POST['del_type']))&&(!empty($_POST['select_type']))){
-      $this->handle->removePrinterType($_POST['select_type']);  
+      $tmp = $this->handle->is_printerTypeUsed($_POST['select_type']);
+      if(count($tmp)){
+        $str = "";
+        foreach($tmp as $id => $name){
+          $str .= $name.", ";
+        }
+        $str = preg_replace("/, $/","",$str); 
+        print_red(sprintf(_("Can't delete printer type, it is still in use by '%s'."),$str));
+      }else{
+        $this->handle->removePrinterType($_POST['select_type']);  
+      }
     }
 
     /* Rename selected printer type to given string
      */
     if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){
-      $this->handle->updatePrinterType($_POST['type_string'],$_POST['select_type']);
+      $tmp = $this->handle->getPrinterTypes();
+      $allok = true;
+      foreach($tmp as $id => $name){
+        if(trim($name) == trim($_POST['type_string'])){
+          $allok = false;
+        }
+      }
+      if($allok){
+        $this->handle->updatePrinterType($_POST['type_string'],$_POST['select_type']);
+      }else{
+        print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['type_string']));
+      }
     }
 
     /* Someone wants to edit the printer types ... 
@@ -467,7 +500,7 @@ class glpiPrinterAccount extends plugin
      *  Assign listbox / checkbox .... values to smarty  
      */
     /* Assign smarty defaults */ 
-    foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments") as $attr){
+    foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments","Cartridges") as $attr){
       $smarty->assign($attr,array());
       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
@@ -506,7 +539,7 @@ class glpiPrinterAccount extends plugin
     */
 
     $divlist = new divSelectBox("glpiAttachmentsList");
-    $divlist-> SetHeight(150);
+    $divlist-> SetHeight(120);
     $atts = $this->getUsedAttachments(true);
     $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
     $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";