Code

Added remove multiple to systems
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 Apr 2007 10:12:19 +0000 (10:12 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 Apr 2007 10:12:19 +0000 (10:12 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6085 594d385d-05f5-0310-b6e9-bd551577e9d8

include/functions_dns.inc
plugins/admin/systems/class_divListSystem.inc
plugins/admin/systems/class_systemManagement.inc
plugins/admin/systems/remove.tpl

index 4754d822889330a454d624c3e329f075ebbe83da..f24ec32473c67c3d1415e0ff87a0bdffc832efa6 100644 (file)
@@ -434,6 +434,13 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName)
   $del    = array();
   $move   = array();
 
+  /* Don't go further if there is nothing to do
+   * Is no account / was no account
+   */
+  if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){
+    return(array("move"=>$move,"add"=>$add,"del"=>$del));
+  }
+
   $zones              = getAvailableZones($config);
   $specialAttributes  = array("cNAMERecord","pTRRecord");
   $newRecords         = array();  // Used to remember which records are removed 
@@ -455,13 +462,6 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName)
     $newEntry['exists'] = false;
   }
 
-  /* Don't go further if there is nothing to do
-   * Is no account / was no account
-   */
-  if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){
-    return(array("move"=>$move,"add"=>$add,"del"=>$del));
-  }
-  
   /* If account was edited prepare some
    *  attributes & arrays ... if required add some 
    *  dns to $move 
index eca9aa779c5948be1486d270d7fecc3277868b24..5615a0bd2e96e3792b3f6cc3eb2ed0c81a9f23f4 100644 (file)
@@ -58,7 +58,12 @@ class divListSystem extends MultiSelectWindow
       $action_col_size += 38;
     }
 
+    /* Toggle all selected / deselected */
+    $chk = "<input type='checkbox' id='select_all' name='select_all'
+               onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+
     /* set Page header */
+    $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("System / Department")));
     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
@@ -187,8 +192,14 @@ class divListSystem extends MultiSelectWindow
     /* Add base selection */
     $listhead .= _("Base")."&nbsp; <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
       " <input class='center' type='image' src='images/list_submit.png' align='middle'
-      title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;".
-      "</div>";
+      title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;";
+
+    /* Multiple options */
+    $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
+        title='"._("Remove selected systems")."' alt='"._("Remove systems")."' name='remove_multiple_systems'>&nbsp;";
+
+    $listhead .="</div>";
+
     $this->SetListHeader($listhead);
   }
 
@@ -331,10 +342,15 @@ class divListSystem extends MultiSelectWindow
       }
 
       $img    = $this->parent->convert_list($val);
+
+      /* Create each field */
+      $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
+                      "attach" => "style='width:20px;'");
+
       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
-      $this->AddElement( array($field1,$field2,$field3));
+      $this->AddElement( array($field0,$field1,$field2,$field3));
     }
 
   }
index 17a371c1937d642f9ba1af14322ada4d754acba9..39e09bdbf29f172385b08ba1ebe46657ed62c233 100644 (file)
@@ -54,7 +54,7 @@ class systems extends plugin
     /* Call parent execute */
     plugin::execute();
 
-    $_SESSION['LOCK_VARS_TO_USE'] = array("/^system_edit_/i","/^system_del_/","/^act/","/^id/");
+    $_SESSION['LOCK_VARS_TO_USE'] = array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/");
 
     /********************
       Check for functional posts, edit|delete|add|... system devices 
@@ -85,6 +85,8 @@ class systems extends plugin
       }elseif(preg_match("/gen_cd_.*/i",$key)){
         $s_action="gen_cd";
         $s_entry  = preg_replace("/gen_cd_/i","",$key);
+      }elseif(preg_match("/^remove_multiple_systems/i",$key)){
+        $s_action="del_multiple";
       }elseif(preg_match("/newsystem_.*/i",$key)){
         $s_action="newsystem";
         $s_entry  = preg_replace("/newsystem_/i","",$key);
@@ -425,6 +427,118 @@ class systems 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->terminals[$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 */
+        $smarty->assign("warning",     sprintf(_("You're about to delete the following user(s) %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_system_confirm'])){
+
+      $ui = get_userinfo();
+      $tabs = array(
+          "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
+          "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
+          "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
+          "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
+          "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
+          "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
+          "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
+
+
+      /* Remove user by user and check acls before removeing them */
+      foreach($this->dns as $key => $dn){
+
+        /* Get 'dn' from posted termlinst */
+        $attrs    = $this->terminals[$key];
+        $type= $this->get_system_type($attrs['objectClass']);
+
+        /* get object type */
+        $tabtype  = "termtabs";
+        $tabobj   = "TERMTABS";
+        $tabacl   = "";
+        if(isset($tabs[$type])){
+          $tabtype = $tabs[$type]['TABCLASS'];
+          $tabobj  = $tabs[$type]['CLASS'];
+          $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
+
+          /* Load permissions for selected 'dn' and check if
+             we're allowed to remove this 'dn' */
+          if(preg_match("/d/",$tabacl)){ 
+
+            /* Delete request is permitted, perform LDAP action */
+            if($tabtype=="phonetabs"){
+              $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
+              $this->systab->set_acl_base($dn);
+              $this->systab->by_object['phonegeneric']->remove_from_parent ();
+            }else{
+              $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
+              $this->systab->set_acl_base($dn);
+              $this->systab->delete();
+            }
+            unset ($this->systab);
+            gosa_log ("System object'".$dn."' has been removed");
+            $this->systab= NULL;
+
+          } 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 ($dn);
+          unset($this->dns[$key]);
+        }
+      }
+    }
+
+    /********************
+      Delete MULTIPLE entries Canceled
+     ********************/
+
+    /* Remove lock */
+   if(isset($_POST['delete_multiple_system_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
     /********************
       Delete system, confirm dialog
      ********************/
@@ -471,6 +585,7 @@ class systems 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 component at '%s'."), @LDAP::fix($this->dn)));
+        $smarty->assign("multiple", false);
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       } else {
 
@@ -699,7 +814,7 @@ class systems extends plugin
 
     /* Add departments if subsearch is disabled */
     if(!$this->DivListSystem->SubSearch){
-      $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
+      $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
     }
     $this->reload();
     $this->DivListSystem->setEntries($this->terminals);
@@ -1080,6 +1195,19 @@ class systems extends plugin
   }
 
 
+  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);
+  }
+
+
   /* !! Incoming dummy acls, required to defined acls for incoming objects
    */
   function plInfo()
index c92e3fb57e619537fb150b5f030cf76b869c747c..dc5dbb2bdf99fbc2318fa53d002a25308498805b 100644 (file)
 </p>
 
 <p class="plugbottom">
-  <input type=submit name="delete_terminal_confirm" value="{t}Delete{/t}">
-  &nbsp;
-  <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+       {if $multiple}
+               <input type=submit name="delete_multiple_system_confirm" value="{t}Delete{/t}">
+               &nbsp;
+               <input type=submit name="delete_multiple_system_cancel" value="{t}Cancel{/t}">
+       {else}
+               <input type=submit name="delete_terminal_confirm" value="{t}Delete{/t}">
+               &nbsp;
+               <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+       {/if}
 </p>