Code

Updated System type & os type management, can't create existing entries, can't delete...
[gosa.git] / plugins / admin / systems / class_glpiPrinterAccount.inc
index ce2cfaca4874e26850baa30ab0cbf3c8172cb32b..2fbffd147c576f7b3b8ebf3862c14208c693cae2 100644 (file)
@@ -21,7 +21,7 @@ class glpiPrinterAccount extends plugin
   
   var $comments           = "";    // Comment
   
-  var $type               = 0;     // System type id
+  var $type               = 0;     // printer type id
   var $serial             = "";   
   var $otherserial        = "";  
   var $ramSize            = 0;
@@ -39,6 +39,8 @@ class glpiPrinterAccount extends plugin
   var $contact            = "";    // Empty
   var $deleted            = "N";   // Deleted entries should have this set to Y
 
+  var $editManufacturer   = false;
+
   /* Not necessary, cause we use mysql databse */
   var $objectclasses= array("whatever");
 
@@ -59,7 +61,7 @@ class glpiPrinterAccount extends plugin
   
   var $usedDevices      = array();  // Which devices are currently selected 
   var $usedAttachments  = array();  // Used Attachments 
-
+  var $usedCartridges   = array();  // Used Cartridges
 
   /* Contructor 
      Sets default values and checks if we already have an existing glpi account
@@ -104,6 +106,14 @@ class glpiPrinterAccount extends plugin
       foreach($atts as $attachment){
         $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc']; 
       }
+
+      $cart= $this->handle->getUsedCartridges($tmp[0]['ID']);
+      foreach($cart as $key => $cartridge){
+        $this->usedCartridges[$key]=$cartridge; 
+        $this->usedCartridges[$key]['status']="exists"; 
+      }
+
+
     }else{
       $this->is_account = false;
     }
@@ -123,6 +133,8 @@ class glpiPrinterAccount extends plugin
     $smarty= get_smarty();
     $display= "";
 
+    $smarty->assign("CartridgesACL",chkacl($this->acl,"Cartridges"));
+
     /*  Assign smarty defaults 
         To avoid undefined indexes, if there is an error with the glpi db
      */ 
@@ -248,13 +260,15 @@ class glpiPrinterAccount extends plugin
     if(isset($_POST['edit_manufacturer'])){
       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
       $this->dialog = true;
+      $this->editManufacturer =true;
     }
 
     /* Close manufacturer editing dialog
      */
-    if(isset($_POST['close_edit_manufacturer'])){
+    if((isset($_POST['close_edit_manufacturer']))&&($this->editManufacturer)){
       $this->dialog = false;
       $this->cur_dialog = false;
+      $this->editManufacturer=false;
     }
 
 
@@ -269,18 +283,19 @@ class glpiPrinterAccount extends plugin
      */
     if(isset($_POST['SelectContactPerson'])){
       $this->addUser = "contact";
-      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
     }
 
     /* Selecte technical responsible person
      */
     if(isset($_POST['SelectTechPerson'])){
       $this->addUser ="tech";
-      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
     }
 
     /* Abort user selection
      */
+    $smarty->assign("AbortSelectUser","SelectUserCancel");
     if(isset($_POST['SelectUserCancel'])){
       $this->dialog = false;
       $this->addUser ="";
@@ -373,6 +388,54 @@ class glpiPrinterAccount extends plugin
       }
     }
 
+    /*  ##########################################################################
+     *  Printer Cartridge handling 
+     */
+
+    /* Abort cartridge select dialog
+     */
+    if(isset($_POST['SelectCartridgeCancel'])){
+      $this->cur_dialog = false;
+      $this->edit_type = false; 
+    }
+
+    /* Get selected cartridges and add them to our list 
+     */ 
+    if(isset($_POST['SelectCartridgeSave'])){
+      $this->cur_dialog->save_object();
+      $carts = $this->cur_dialog->save();
+      foreach($carts as $cart){
+        $cart['status'] = "new";
+        $this->usedCartridges[] = $cart;
+      }
+      $this->cur_dialog = false;
+      $this->edit_type = false; 
+    }
+
+    /* Remove cartridge  
+     */
+    if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges']))){
+
+      foreach($_POST['Cartridges'] as $cartID){
+
+        if(isset($this->usedCartridges[$cartID])){
+          if($this->usedCartridges[$cartID]['status'] == "exists"){
+            $this->usedCartridges[$cartID]['status'] = "deleted";
+          }else{
+            unset($this->usedCartridges[$cartID]);
+          }
+        }
+      }
+    }
+
+    /* Open Attachment pool to add/edit Attachments
+     */
+    if(isset($_POST['AddCartridge'])){
+      $this->cur_dialog = new glpiPrinterCartridges($this->config,$this->dn,$this->type);
+      $this->dialog = true;
+    }
+
+
     /*  ##########################################################################
      *  Draw Dialogs
      */
@@ -433,6 +496,10 @@ class glpiPrinterAccount extends plugin
     $smarty->assign("Attachments",            $this->getUsedAttachments());
     $smarty->assign("AttachmentKeys",         array_flip($this->getUsedAttachments()));
 
+    /* Assign Cartridges 
+     */
+    $smarty->assign("Cartridges",            $this->getUsedCartridges());
+    $smarty->assign("CartridgeKeys",         $this->getUsedCartridges(true));
 
     /*  ##########################################################################
      *  Assign contact and technical responsible person 
@@ -462,6 +529,19 @@ class glpiPrinterAccount extends plugin
       $smarty->assign("tech_num",               _("N/A"));
     }
 
+    /* If theres a cartridge selected, you can't change the printer type.
+     */ 
+    $disp = true;
+
+    foreach($this->usedCartridges as $cart){
+      if($cart['status'] != "deleted"){
+        $disp = false;
+      }
+    }
+    if($disp==false){
+      $smarty->assign("typeACL","disabled");
+    }
+
     $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
     return($display);
   }
@@ -478,18 +558,20 @@ class glpiPrinterAccount extends plugin
   /* Save data to object */
   function save_object()
   {
-    plugin::save_object();
-    foreach($this->attributes as $attrs){
-      if(isset($_POST[$attrs])){
-        $this->$attrs = $_POST[$attrs];
+    if(isset($_POST['glpiPrinterFlagsPosted'])){
+      plugin::save_object();
+      foreach($this->attributes as $attrs){
+        if(isset($_POST[$attrs])){
+          $this->$attrs = $_POST[$attrs];
+        }
       }
-    }
 
-    foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
-      if(isset($_POST[$checkboxes])){
-        $this->$checkboxes = 1;
-      }else{
-        $this->$checkboxes = 0;
+      foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
+        if(isset($_POST[$checkboxes])){
+          $this->$checkboxes = 1;
+        }else{
+          $this->$checkboxes = 0;
+        }
       }
     }
 
@@ -527,6 +609,14 @@ class glpiPrinterAccount extends plugin
       }
       $tmp = $this->handle->getPrinterInformations($this->dn);
       $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
+
+      foreach($this->usedCartridges as $cart){
+        if($cart['status'] == "deleted"){
+          $this->handle->removeCartridgeFromPrinter($cart['ID']);
+        }elseif($cart['status'] == "new"){
+          $this->handle->addCartridgeFromPrinter($tmp[0]['ID'],$cart['type_ID']);
+        }
+      }
     }
   }
 
@@ -551,7 +641,20 @@ class glpiPrinterAccount extends plugin
     }
     return($ret);
   }
-  
+
+  function getUsedCartridges($flip = false)
+  {
+    $ret = array();
+    foreach($this->usedCartridges as $key => $value){
+      if($value['status'] == "deleted") continue;
+      if($flip){
+        $ret[$key] = $key;    
+      }else{
+        $ret[$key] = $value['name']." [".$value['type_name']."] "._("since")." :".$value['date_use'];
+      }
+    }
+    return($ret);
+  }  
 
 }