Code

Added branches container for old stuff
[gosa.git] / gosa-plugins / goto / admin / devices / class_deviceManagement.inc
index 6972caefa8d1069ca5fc529179b6cf5a64d35cb3..08921f09ce7a6fa40fff49dbc417cc0d7beba68e 100644 (file)
@@ -6,6 +6,7 @@ class deviceManagement extends plugin
   /* Definitions */
   var $plHeadline     = "Hotplug devices";
   var $plDescription  = "Manage hotplug devices";
+  var $plIcon         = "plugins/goto/images/devices.png";
 
   /* Dialog attributes */
   var $ui                             = NULL;
@@ -16,6 +17,9 @@ class deviceManagement extends plugin
   var $CopyPasteHandler               = NULL;
   var $start_pasting_copied_objects;
   var $dn ="";
+  var $dns = array();
+
+  var $acl_module = array("devices");
 
   function deviceManagement(&$config, $dn= NULL)
   {
@@ -23,7 +27,7 @@ class deviceManagement extends plugin
     $this->ui = get_userinfo();  
 
     /* Check if copy & paste is activated */
-    if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
+    if($this->config->get_cfg_value("copyPaste") == "true"){
       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
     }
 
@@ -43,7 +47,7 @@ class deviceManagement extends plugin
 
     /* These vars will be stored if you try to open a locked device,
         to be able to perform your last requests after showing a warning message */
-    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^device_edit_/",
+    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^device_edit_/","/^menu_action/",
                                           "/^device_del_/","/^item_selected/","/^remove_multiple_devices/"));
 
     $smarty       = get_smarty();             // Smarty instance
@@ -143,8 +147,7 @@ class deviceManagement extends plugin
 
     /* Cancel dialogs */
     if (isset($_POST['edit_cancel']) && is_object($this->devicetabs)){
-      del_lock ($this->devicetabs->dn);
-      unset ($this->devicetabs);
+      $this->remove_lock();
       $this->devicetabs= NULL;
       session::un_set('objectinfo');
     }
@@ -166,17 +169,23 @@ class deviceManagement extends plugin
       if (count($message) == 0){
 
         /* Save data data to ldap */
-#        $this->devicetabs->set_release($this->DivListDevices->selectedRelease);
         $this->devicetabs->save();
 
         if (!isset($_POST['edit_apply'])){
+
           /* device type has been saved successfully, remove lock from LDAP. */
           if ($this->dn != "new"){
-            del_lock ($this->dn);
+            $this->remove_lock();
           }
           unset ($this->devicetabs);
           $this->devicetabs= NULL;
           session::un_set('objectinfo');
+        }else{
+
+          /* Reinitialize tab */
+          if($this->devicetabs instanceof tabs){
+            $this->devicetabs->re_init();
+          }
         }
       } else {
        /* Ok. There seem to be errors regarding to the tab data,
@@ -222,24 +231,39 @@ class deviceManagement extends plugin
 
       if(count($ids)){
 
+        $disallowed = array();
         foreach($ids as $id){
           $dn = $this->devices[$id]['dn'];
-          if (($user= get_lock($dn)) != ""){
-            return(gen_locked_message ($user, $dn));
+          $acl = $this->ui->get_permissions($dn, "devices/deviceGeneric");
+          if(preg_match("/d/",$acl)){
+            $this->dns[$id] = $dn;
+          }else{
+            $disallowed[] = $dn;
           }
-          $this->dns[$id] = $dn;
         }
 
-        $dns_names = array();
-        foreach($this->dns as $dn){
-          add_lock ($dn, $this->ui->dn);
-          $dns_names[] =@LDAP::fix($dn);
+        if(count($disallowed)){
+          msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
         }
 
-        /* Lock the current entry, so nobody will edit it during deletion */
-        $smarty->assign("intro", msgPool::deleteInfo($dns_names),_("device"));
-        $smarty->assign("multiple", true);
-        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+        if(count($this->dns)){
+
+          /* Check locks */
+          if ($user= get_multiple_locks($this->dns)){
+            return(gen_locked_message($user,$this->dns));
+          }
+
+          $dns_names = array();
+          foreach($this->dns as $dn){
+            $dns_names[] =@LDAP::fix($dn);
+          }
+          add_lock ($this->dns, $this->ui->dn);
+
+          /* Lock the current entry, so nobody will edit it during deletion */
+          $smarty->assign("intro", msgPool::deleteInfo($dns_names),_("device"));
+          $smarty->assign("multiple", true);
+          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+        }
       }
     }
 
@@ -272,10 +296,11 @@ class deviceManagement extends plugin
           msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
           new log("security","devices/".get_class($this),$dn,array(),"Tried to trick deletion.");
         }
-        /* Remove lock file after successfull deletion */
-        del_lock ($dn);
-        unset($this->dns[$key]);
       }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -285,10 +310,10 @@ class deviceManagement extends plugin
 
     /* Remove lock */
     if(isset($_POST['delete_multiple_device_cancel'])){
-      foreach($this->dns as $key => $dn){
-        del_lock ($dn);
-        unset($this->dns[$key]);
-      }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -358,7 +383,8 @@ class deviceManagement extends plugin
       }
 
       /* Remove lock file after successfull deletion */
-      del_lock ($this->dn);
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -368,9 +394,9 @@ class deviceManagement extends plugin
 
     /* Delete device canceled? */
     if (isset($_POST['delete_cancel'])){
-      del_lock ($this->dn);
+      $this->remove_lock();
       session::un_set('objectinfo');
-  }
+    }
 
     /* Show tab dialog if object is present */
     if (($this->devicetabs) && (isset($this->devicetabs->config))){
@@ -398,7 +424,7 @@ class deviceManagement extends plugin
 
         /* Check if there is a snapshot dialog open */
     $base = $this->DivListDevices->selectedBase;
-    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
+    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
       return($str);
     }
 
@@ -433,13 +459,20 @@ class deviceManagement extends plugin
       return("");
     }
 
+    $ui = get_userinfo();
+
     /* Add a single entry to queue */
     if($s_action == "cut" || $s_action == "copy"){
 
       /* Cleanup object queue */
       $this->CopyPasteHandler->cleanup_queue();
       $dn = $this->devices[$s_entry]['dn'];
-      $this->CopyPasteHandler->add_to_queue($dn,$s_action,"devicetabs","DEVICETABS","devices");
+      if($s_action == "copy" && $ui->is_copyable($dn,"devices","deviceGeneric")){ 
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"devicetabs","DEVICETABS","devices");
+      }
+      if($s_action == "cut" && $ui->is_cutable($dn,"devices","deviceGeneric")){ 
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"devicetabs","DEVICETABS","devices");
+      }
     }
 
     /* Add entries to queue */
@@ -452,10 +485,10 @@ class deviceManagement extends plugin
       foreach($this->list_get_selected_items() as $id){
         $dn = $this->devices[$id]['dn'];
 
-        if($s_action == "copy_multiple"){
+        if($s_action == "copy_multiple" && $ui->is_copyable($dn,"devices","deviceGeneric")){ 
           $this->CopyPasteHandler->add_to_queue($dn,"copy","devicetabs","DEVICETABS","devices");
         }
-        if($s_action == "cut_multiple"){
+        if($s_action == "cut_multiple" && $ui->is_cutable($dn,"devices","deviceGeneric")){
           $this->CopyPasteHandler->add_to_queue($dn,"cut","devicetabs","DEVICETABS","devices");
         }
       }
@@ -470,8 +503,8 @@ class deviceManagement extends plugin
     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
 
       /* Get dialog */
-      $data = $this->CopyPasteHandler->execute();
       $this->CopyPasteHandler->SetVar("base",$this->DivListDevices->selectedBase);
+      $data = $this->CopyPasteHandler->execute();
 
       /* Return dialog data */
       if(!empty($data)){
@@ -506,9 +539,15 @@ class deviceManagement extends plugin
     }
 
     /* Get results and create index */
-    $res= get_sub_list($Filter,"devices",get_ou('deviceou'), $base, array("cn","description","dn","objectClass"), $Flags);
+    $res= get_sub_list($Filter,"devices",get_ou('deviceou'), $base, array("cn","gotoHotplugDevice","description","dn","objectClass"), $Flags);
     $tmp2 = array();
     foreach ($res as $val){
+      if (!isset($val['description']) && isset($val['gotoHotplugDevice'][0])) {
+        $dsc= preg_replace("/\|.*$/", "", $val['gotoHotplugDevice'][0]);
+        if ($dsc != ""){
+          $val['description']= array("count" => 1, 0 => $dsc);
+        }
+      }
       $tmp2[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']] = strtolower($val['cn'][0]).$val['cn'][0].$val['dn'];
       $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
     }
@@ -525,8 +564,11 @@ class deviceManagement extends plugin
 
   function remove_lock()
   {
-    if (isset($this->devicetabs->dn)){
-      del_lock ($this->devicetabs->dn);
+    if (isset($this->dn) && !empty($this->dn)){
+      del_lock ($this->dn);
+    }
+    if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
+      del_lock ($this->dns);
     }
   }