Code

Some modifications
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 3 Jan 2006 14:07:01 +0000 (14:07 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 3 Jan 2006 14:07:01 +0000 (14:07 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2396 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_glpiAccount.inc
plugins/admin/systems/class_glpiDeviceManagement.inc
plugins/admin/systems/glpiDeviceManagement.tpl

index 117aa379252699a08db0270f4e689ce3deb0e490..a24c3382af4e34bb89133b346fb79e2532574d01 100644 (file)
@@ -111,6 +111,21 @@ class glpiAccount extends plugin
       $this->cur_dialog = new glpiDeviceManagement($this->config,$this->dn);
     }
 
+    /* We have selected some devices and pressed use button */
+    if(isset($_POST['SelectDeviceSave'])){
+      $this->cur_dialog->save_object();
+      print_a($this->cur_dialog->getSelected());
+      $this->cur_dialog = false;
+      $this->dialog = false;
+      $this->edit_type=false;
+    }
+
+    /* Aborted Device selction */
+    if(isset($_POST['SelectDeviceCancel'])){
+      $this->dialog = false;
+      $this->cur_dialog = false;
+      $this->edit_type=false;
+    }
 
     /* System type management
      */
index 195bea382e3d3d52f1134c40ff8ce21b218c48d5..f235666999e74839ff1b429fcc41e496f19e6031 100644 (file)
@@ -22,6 +22,7 @@ class glpiDeviceManagement extends plugin
   var $DeviceAttrs = array();
   var $AllowedDevices = array();
 
+  var $Selected = array();
 
   function glpiDeviceManagement ($config, $dn= NULL)
   {
@@ -147,10 +148,17 @@ class glpiDeviceManagement extends plugin
     $editdel = "<a href='?plug=".$_GET['plug']."&amp;act=edit_device&amp;id=%s'><img src='images/edit.png' alt='"._("Edit")."' border=0></a>";
     $editdel.= "<a href='?plug=".$_GET['plug']."&amp;act=del_device&amp;id=%s'><img src='images/edittrash.png' alt='"._("Delete")."' border=0></a>";
     
-    $useDevice = "<input type='checkbox' value='%s' name='useDevice_%s' >";
+    $useDevice = "<input type='hidden' name='wasOnPage_%s' value='%s'><input type='checkbox' value='%s' name='useDevice_%s' %USE%>";
 
     foreach($this->devices as $key=>$user){
-      $field1 = array("string" => sprintf($useDevice,base64_encode($key),base64_encode($key)), "attach" => "style='text-align:center;width:20px;'");
+
+      if(isset($this->Selected[$user['device_type']][$user['designation']])){
+        $use = " checked ";
+      }else{
+        $use ="";
+      }
+
+      $field1 = array("string" => preg_replace("/%s/",base64_encode($key),preg_replace("/%USE%/",$use,$useDevice)), "attach" => "style='text-align:center;width:20px;'");
       $field2 = array("string" => sprintf($edit,base64_encode($key),$user['designation']."&nbsp;[".$user['comment']."]"), "attach" => "style=''");
       $field3 = array("string" => sprintf($editdel,base64_encode($key),base64_encode($key)), 
         "attach" => "style='width:60px;border-right:0px;text-align:right;'");
@@ -226,6 +234,24 @@ class glpiDeviceManagement extends plugin
   */
   function save_object()
   {
+    foreach($_POST as $name => $value){
+      if(preg_match("/wasOnPage_/",$name)){
+        $dN = base64_decode($value);
+
+        $device = $this->devices[$dN];
+        $type   = $device['device_type'];  
+            
+
+        if(isset($_POST['useDevice_'.$value])){
+          $this->Selected[$type][$device['designation']] = $device;
+        }else{
+          if(isset($this->Selected[$type][$device['designation']])){
+            unset($this->Selected[$type][$device['designation']]);
+          }
+        }
+      }
+    }
+
     if(is_array($this->EditEntry)){
       foreach($this->EditEntry as $name => $value){
         if(isset($_POST[$name])){
@@ -236,6 +262,12 @@ class glpiDeviceManagement extends plugin
     }
   }
 
+  /* returns the selected devices */
+  function getSelected()
+  {
+    return($this->Selected); 
+  }
+
   /* This function cehck all created devices if you wan't to create device specific check 
       use >>if($attr['device_type']=="moboard")<< to create a device type depending check
   */
@@ -245,6 +277,23 @@ class glpiDeviceManagement extends plugin
     if(empty($attr['designation'])){
       $message[]=(_("You have to specify a valid name for this device."));
     }
+
+    /* Avoid same name twice */
+    $devices = ($this->parent->handle->getDevices());
+    foreach($devices as $dev){
+      if($dev['designation']==$attr['designation']){
+
+        /* Entries with ['ID'] already exists, and are only edited, if ID is missing we are currently creating a new entry */
+        if(isset($attr['ID'])){
+          if(!(($dev['ID'] == $attr['ID'])&&($dev['device_type']==$attr['device_type']))){
+            $message[] = _("This device name is already in use.");
+          }
+        }else{
+          $message[] = _("This device name is already in use.");
+        }
+      }
+    }
+
     return($message);
   }
 
index 9c64ae60a0a3e4a5a243b41b151821eb8ba2ee82..03f2d562e36c6166e0101c0b25bfe9acae269392 100644 (file)
@@ -49,5 +49,6 @@
 <input type="hidden" name="ignore">
 <p class="seperator">&nbsp;</p>
 <div align="right">
-       <input type="submit" name="SelectUserCancel" value="{t}Cancel{/t}">
+       <input type="submit" name="SelectDeviceSave" value="{t}Use{/t}">
+       <input type="submit" name="SelectDeviceCancel" value="{t}Cancel{/t}">
 </div>