Code

Added rename dialog
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 28 Feb 2006 07:58:43 +0000 (07:58 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 28 Feb 2006 07:58:43 +0000 (07:58 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2759 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_glpiPrinterAccount.inc
plugins/admin/systems/glpi_edit_printer_type.tpl

index c6185e46c9595d4a1aaef0276d750659b7d2d95d..abaa32acb67dccdee0244424b772778fc6dd5423 100644 (file)
@@ -39,6 +39,9 @@ class glpiPrinterAccount extends plugin
   var $contact            = "";    // Empty
   var $deleted            = "N";   // Deleted entries should have this set to Y
 
+  var $rename             = false;
+  var $select_type        ;
+
   var $editManufacturer   = false;
 
   /* Not necessary, cause we use mysql databse */
@@ -207,6 +210,29 @@ class glpiPrinterAccount extends plugin
      *  Dialog 
      */
 
+    /* Rename was requested */
+    if(isset($_POST['Rename_PType_OK'])){
+      $tmp = $this->handle->getPrinterTypes();
+      $allok = true;
+      foreach($tmp as $id => $name){
+        if(trim($name) == trim($_POST['string'])){
+          $allok = false;
+        }
+      }
+      if($allok){
+        $this->handle->updatePrinterType($_POST['string'],$this->select_type);
+        $this->rename = false;
+      }else{
+        print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['string']));
+      }
+    }
+
+    /* abort rename 
+     */
+    if(isset($_POST['Rename_Cancel'])){
+      $this->rename = false;
+    }
+
     /* Printer type management
      */
     if(isset($_POST['edit_type'])){
@@ -257,25 +283,30 @@ class glpiPrinterAccount extends plugin
 
     /* Rename selected printer type to given string
      */
-    if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){
+    if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))||($this->rename)){
+      $this->rename = true;
+
+      $smarty->assign("Method","rename");
+
       $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']));
+
+      if(isset($_POST['select_type'])){
+        $this->select_type = $_POST['select_type'];
+      }  
+      $smarty->assign("string",$tmp[$this->select_type]);
+      if(isset($_POST['string'])){
+        $smarty->assign("string",$_POST['string']);
       }
-    }
+
+      $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
+      return($display);
+    }  
 
     /* Someone wants to edit the printer types ... 
        So, lets open a new dialog which provides some buttons to edit the types
      */
     if($this->edit_type){
+      $smarty->assign("Method","edit");
       $smarty->assign("PrinterTypes",            $this->handle->getPrinterTypes());
       $smarty->assign("PrinterTypeKeys",         array_flip($this->handle->getPrinterTypes()));
       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
index 108a6c2a71e93722aeaf8570cbc5f7ec9343b011..3e3bf2d3ac920553e7dedfeb3e5135462ebc8c78 100644 (file)
@@ -1,18 +1,31 @@
 <br>
-     <select name="select_type" size="12" style="width:100%">
-                            {html_options values=$PrinterTypeKeys output=$PrinterTypes}
-     </select><br>
+{if $Method == "edit"}
+        <select name="select_type" size="12" style="width:100%">
+                                                       {html_options values=$PrinterTypeKeys output=$PrinterTypes}
+        </select><br>
         <input name="type_string">
         <input type="submit" name="add_type"           value="{t}Add{/t}" >
         <input type="submit" name="rename_type"        value="{t}Rename{/t}" >
         <input type="submit" name="del_type"           value="{t}Delete{/t}" >
 
-<p class="seperator">&nbsp;</p>
-<div align="right">
-<p>
-<input name="close_edit_type" value="{t}Close{/t}" type="submit">
-</p>
-</div>
+       <p class="seperator">&nbsp;</p>
+       <div align="right">
+               <p>
+                       <input name="close_edit_type" value="{t}Close{/t}" type="submit">
+               </p>
+       </div>
+{else}
+
+       {t}Please enter a new name{/t}&nbsp;<input name="string" value="{$string}">
+       <p class="seperator">&nbsp;</p>
+    <p>
+        <div align="right" style="text-align: right;">
+            <input type="submit" name="Rename_PType_OK"       value="{t}Rename{/t}" >
+            <input type="submit" name="Rename_Cancel"   value="{t}Cancel{/t}" >
+        </div>
+    </p>
+{/if}
+
 <script language="JavaScript" type="text/javascript">
   <!-- // First input field on page
   document.mainform.type_string.focus();