Code

Fixed problem with not clickable buttons in fai package error msgs
[gosa.git] / plugins / admin / fai / class_faiManagement.inc
index 1bcc95816fea23ddbbd01a7cca4dc65bc5dfd0c3..1922b2aadf0e27d2ce4033b9dec16bf8a9eef020 100644 (file)
@@ -56,6 +56,8 @@ class faiManagement extends plugin
   var $dispNewFreeze= false;
 
   var $DivListFai;
+  var $start_pasting_copied_objects = FALSE;
+  var $CopyPasteHandler = FALSE;
 
        /* construction/reconstruction 
         */
@@ -84,7 +86,7 @@ class faiManagement extends plugin
                $s_entry        = "";
     
     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
-    $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
+    $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/");
 
 
     /****************
@@ -99,7 +101,10 @@ class faiManagement extends plugin
                     "/create_script/i"=>"new_script",      "/create_hook/i"=>"new_hook",
                     "/create_variable/i"=>"new_variable",  "/create_template/i"=>"new_template",
                     "/create_package/i"=>"new_package",    "/create_profile/i"=>"new_profile",
-                    "/edit_continue/"=>"select_class_name_finished");
+                    "/edit_continue/"=>"select_class_name_finished",
+                    "/^multiple_copy_fai/" => "copy_multiple", 
+                    "/^multiple_cut_fai/" => "cut_multiple", 
+                    "/^remove_multiple_fai_objects/" => "del_multiple");
 
                foreach($_POST as $name => $value){
       foreach($posts as $reg => $act ){
@@ -144,14 +149,14 @@ class faiManagement extends plugin
 
                if ($s_action=="delete"){
 
+      /* Get 'dn' from posted termlinst */
+      $this->dn= $this->objects[$s_entry]['dn'];
+
                        /* Load permissions for selected 'dn' and check if
                           we're allowed to remove this 'dn' */
       $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
       if(preg_match("/d/",$acl)){
 
-        /* Get 'dn' from posted termlinst */
-        $this->dn= $this->objects[$s_entry]['dn'];
-
                                /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
                                if (($user= get_lock($this->dn)) != ""){
                                        return(gen_locked_message ($user, $this->dn));
@@ -160,6 +165,7 @@ class faiManagement extends plugin
                                /* Lock the current entry, so nobody will edit it during deletion */
                                add_lock ($this->dn, $this->ui->dn);
                                $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
+        $smarty->assign("multiple", false);
                                return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
                        } else {
 
@@ -170,6 +176,103 @@ class faiManagement extends plugin
                }
 
 
+    /********************
+      Delete MULTIPLE entries requested, display confirm dialog
+     ********************/
+
+    if ($s_action=="del_multiple"){
+      $this->dns = array();
+      $ids = $this->list_get_selected_items();
+
+      if(count($ids)){
+
+        foreach($ids as $id){
+          $dn = $this->objects[$id]['dn'];
+          if (($user= get_lock($dn)) != ""){
+            return(gen_locked_message ($user, $dn));
+          }
+          $this->dns[$id] = $dn;
+        }
+
+        $dns_names = "<br><pre>";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $dns_names .="</pre>";
+
+        /* Lock the current entry, so nobody will edit it during deletion */
+        if (count($this->dns) == 1){
+          $smarty->assign("warning",     sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
+        } else {
+          $smarty->assign("warning",     sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
+        }
+        $smarty->assign("multiple", true);
+        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+      }
+    }
+
+
+    /********************
+      Delete MULTIPLE entries confirmed
+     ********************/
+
+    /* Confirmation for deletion has been passed. Users should be deleted. */
+    if (isset($_POST['delete_multiple_fai_object_confirm'])){
+
+      /* Find out more about the object type */
+      $ldap   = $this->config->get_ldap_link();
+
+      /* Remove user by user and check acls before removeing them */
+      foreach($this->dns as $key => $dn){
+
+        $ldap->cat($dn, array('objectClass'));
+        $attrs  = $ldap->fetch();
+        $type   = $this->get_type($attrs);
+
+        $acl  = $this->ui->get_permissions($dn,"fai/".$type[1]);
+        if(preg_match("/d/",$acl)){
+
+          $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
+          $this->dialog->set_acl_base($dn);
+          $this->dialog->by_object[$type[1]]->remove_from_parent ();
+          unset ($this->dialog);
+          $this->dialog= NULL;
+          $to_del = clean_up_releases($dn);
+          save_release_changes_now();
+
+          foreach($to_del as $dn){
+            $ldap->rmdir_recursive($dn);
+          }
+
+        } else {
+
+          /* Normally this shouldn't be reached, send some extra
+             logs to notify the administrator */
+          print_red (_("You are not allowed to delete this component!"));
+          new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
+        }
+
+        /* Remove lock file after successfull deletion */
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
+    /********************
+      Delete MULTIPLE entries Canceled
+     ********************/
+
+    /* Remove lock */
+    if(isset($_POST['delete_multiple_fai_object_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
     /****************
       Delete aborted  
      ****************/
@@ -185,44 +288,48 @@ class faiManagement extends plugin
      ****************/
 
                /* Deltetion was confirmed, so delete this entry
-                */
-               if (isset($_POST['delete_terminal_confirm'])){
-
-                       /* Some nice guy may send this as POST, so we've to check
-                          for the permissions again. */
-      $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
-      if(preg_match("/d/",$acl)){
+     */
+    if (isset($_POST['delete_terminal_confirm'])){
+
+      /* Some nice guy may send this as POST, so we've to check
+         for the permissions again. */
+
+      /* Find out more about the object type */
+      $ldap      = $this->config->get_ldap_link();
+      $ldap->cat($this->dn, array('objectClass'));
+      if($ldap->count()){
+        $attrs = $ldap->fetch();
+        $type    = $this->get_type($attrs);                    
+
+        $acl  = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
+        if(preg_match("/d/",$acl)){
+
+          $this->dialog = new $type[0]($this->config,  $this->config->data['TABS'][$type[2]], $this->dn,"fai");
+          $this->dialog->set_acl_base($this->dn);
+          $this->dialog->by_object[$type[1]]->remove_from_parent ();
+          unset ($this->dialog);
+          $this->dialog= NULL;
+          $to_del = clean_up_releases($this->dn);
+          save_release_changes_now();
+
+          foreach($to_del as $dn){
+            $ldap->rmdir_recursive($dn);
+          }
 
-                               /* Find out more about the object type */
-                               $ldap     = $this->config->get_ldap_link();
-                               $ldap->cat($this->dn, array('objectClass'));
-                               $attrs  = $ldap->fetch();
-                               $type     = $this->get_type($attrs);                    
-                               $this->dialog = new $type[0]($this->config,     $this->config->data['TABS'][$type[2]], $this->dn);
-                               $this->dialog->by_object[$type[1]]->remove_from_parent ();
-                               unset ($this->dialog);
-                               gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
-                               $this->dialog= NULL;
-        $to_del = clean_up_releases($this->dn);
-        save_release_changes_now();
+        } else {
 
-        foreach($to_del as $dn){
-          $ldap->rmdir_recursive($dn);
-          gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
+          /* Normally this shouldn't be reached, send some extra
+             logs to notify the administrator */
+          print_red (_("You are not allowed to delete this component!"));
+          new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
         }
 
-                       } else {
-
-                               /* Normally this shouldn't be reached, send some extra
-                                  logs to notify the administrator */
-                               print_red (_("You are not allowed to delete this component!"));
-                               gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
-                                               "deletion.");
-                       }
-
-                       /* Remove lock file after successfull deletion */
-                       del_lock ($this->dn);
-               }
+      }else{
+        print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn));
+      }
+      /* Remove lock file after successfull deletion */
+      del_lock ($this->dn);
+    }
 
 
     /****************
@@ -240,7 +347,8 @@ class faiManagement extends plugin
                        }
                        add_lock ($this->dn, $this->ui->dn);
 
-                       $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
+                       $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
+      $this->dialog->set_acl_base($this->dn);
                        $this->is_dialog  = true;
 
       if($entry['FAIstate'] == "freeze"){
@@ -301,6 +409,8 @@ class faiManagement extends plugin
         $this->lock_name   = $name;
         $this->lock_dn     = $bb;
         $this->postremove();
+
+        new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
       }
     }
 
@@ -396,8 +506,17 @@ class faiManagement extends plugin
         $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ; 
 
         /* Print header to have styles included */
-        echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
-        echo "<body style='background-image:none;margin:3px;color:black'>";
+        echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+          <html>
+          <head>
+          <title></title>
+          <style type="text/css">@import url("themes/default/style.css");</style>
+          <script language="javascript" src="include/focus.js" type="text/javascript"></script>
+          </head>
+          <body style="background: none;margin:3px;color:black">
+          ';
+
+        new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
 
         /* Duplicate applications 
          */
@@ -413,7 +532,7 @@ class faiManagement extends plugin
          */
         $ldap->cat($mimesrc,array("dn")) ;
         if($ldap->count()){
-          $ldap->cd ($appdst);
+          $ldap->cd ($mimedst);
           $ldap->recursive_remove();
           $ldap->cd ($this->config->current['BASE']);
           $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
@@ -443,6 +562,8 @@ class faiManagement extends plugin
           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
           </form></div>";
 
+        echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
+
         /* Print footer to have valid html */
         echo "</body></html>";
 
@@ -510,7 +631,9 @@ class faiManagement extends plugin
       $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
       if(preg_match("/c/",$acl)){
         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
-        $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
+        $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
+        $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
+
         $this->is_dialog = false;
       }else{
         print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
@@ -533,8 +656,8 @@ class faiManagement extends plugin
         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
         $name = $this->dialog->save();
 
-        $this->dialog = new $a_setup[0]($this->config,
-            $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
+        $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
+        $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
         $this->dialog->by_object[$a_setup[1]]->cn = $name;
         $this->is_dialog = true;
       }                
@@ -642,7 +765,7 @@ class faiManagement extends plugin
     /* Display dialog with system list */
     $this->DivListFai->parent = $this;
     $this->DivListFai->execute();
-    $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
+    $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
     $this->reload();
     $this->DivListFai->setEntries($this->objects);
     return($this->DivListFai->Draw());
@@ -679,9 +802,21 @@ class faiManagement extends plugin
     }
     return ($ret);
   }
-
   
 
+  function list_get_selected_items()
+  {
+    $ids = array();
+    foreach($_POST as $name => $value){
+      if(preg_match("/^item_selected_[0-9]*$/",$name)){
+        $id   = preg_replace("/^item_selected_/","",$name);
+        $ids[$id] = $id;
+      }
+    }
+    return($ids);
+  }
+
+
   /* reload list of objects */
   function reload()
   {
@@ -703,21 +838,28 @@ class faiManagement extends plugin
 
     $this->lock_type = get_release_tag(get_release_dn($base));
 
-    /* Get resolved release dependencies */
-    $tmp = get_all_objects_for_given_base($base,"(&(|(objectClass=FAIpartitionTable)(objectClass=FAIpackageList)(objectClass=FAIscript)
-      (objectClass=FAIvariable)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAItemplate))(cn=$Regex))");
-
     /* Create a new list of FAI object 
      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
      */
     $ObjectTypes = array(
-        "FAIpartitionTable"  => array("OU"=>"ou=disk,"        , "CHKBOX"=>"ShowPartitions"),
-        "FAIpackageList"     => array("OU"=>"ou=packages,"    , "CHKBOX"=>"ShowPackages"),
-        "FAIscript"          => array("OU"=>"ou=scripts,"     , "CHKBOX"=>"ShowScripts"),
-        "FAIvariable"        => array("OU"=>"ou=variables,"   , "CHKBOX"=>"ShowVariables"),
-        "FAIhook"            => array("OU"=>"ou=hooks,"       , "CHKBOX"=>"ShowHooks"),
-        "FAIprofile"         => array("OU"=>"ou=profiles,"    , "CHKBOX"=>"ShowProfiles"),
-        "FAItemplate"        => array("OU"=>"ou=templates,"   , "CHKBOX"=>"ShowTemplates"));
+        "FAIpartitionTable"  => array("OU"=>"ou=disk,"        , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
+        "FAIpackageList"     => array("OU"=>"ou=packages,"    , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
+        "FAIscript"          => array("OU"=>"ou=scripts,"     , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
+        "FAIvariable"        => array("OU"=>"ou=variables,"   , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
+        "FAIhook"            => array("OU"=>"ou=hooks,"       , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
+        "FAIprofile"         => array("OU"=>"ou=profiles,"    , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
+        "FAItemplate"        => array("OU"=>"ou=templates,"   , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
+
+    $filter = "";
+    foreach($ObjectTypes as $key => $data){
+      if($this->DivListFai->$data['CHKBOX']){
+        $filter.= "(objectClass=".$key.")";
+      }
+    }
+    $filter = "(&(|".$filter.")(cn=$Regex))";
+    
+    /* Get resolved release dependencies */
+    $tmp = get_all_objects_for_given_base($base,$filter);
 
     /* Ge listed ldap objects */
     $ldap = $this->config->get_ldap_link();
@@ -731,12 +873,9 @@ class faiManagement extends plugin
       /* Walk through possible types */
       foreach($ObjectTypes as $type => $rest){  
 
-        /* Skip all unchecked types */
-        if(! $this->DivListFai->$rest['CHKBOX']){
-          continue;
-        }
+        $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
 
-        if(in_array($type,$object['objectClass'])){
+        if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
 
           /* Prepare object */
           unset($object['objectClass']['count']);
@@ -748,6 +887,7 @@ class faiManagement extends plugin
           $obj                  = array();
           $obj['cn']                         = $object['cn'][0];
           $obj['dn']                         = $object['dn'];
+          $obj['acl']                      = $acl;
           $obj['description']   = $object['description'][0];
           $obj['objectClass']   = $object['objectClass'];