Code

Shrinked down aclRole class to half size.
[gosa.git] / plugins / admin / acl / class_divListACL.inc
index bf2d2ef94a48dfe2001da362be18c59f0876d051..56fe9ae35a6626d23a1953af9f66c9060801248a 100644 (file)
@@ -17,12 +17,12 @@ class divListACL extends MultiSelectWindow
 
   var $parent             ;
   var $ui                 ;
-
+  var $action_col_size;
   
 
   function divListACL ($config,$parent)
   {
-    MultiSelectWindow::MultiSelectWindow($config, "ACLs", "acls");
+    MultiSelectWindow::MultiSelectWindow($config, "ACLs", "acl");
     
     $this->parent       = $parent;
     $this->ui           = get_userinfo();
@@ -41,54 +41,99 @@ class divListACL extends MultiSelectWindow
     $this->EnableCloseButton(false);
     $this->EnableSaveButton (false);
 
-    /* Dynamic action col, depending on snapshot icons */
-    $action_col_size = 80;
+    /* Dynamic action col */
+    $this->action_col_size = 120;
 
     /* set Page header */
     $this->AddHeader(array("string"=>" ",          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("Summary")));
-    $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
+    $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$this->action_col_size."px;border-right:0px;text-align:right;'"));
 
     /* Set dynamically filter checkboxes */
     $this->set_filter_objectclasses();   
  
     /* Add SubSearch checkbox */
-    $this->AddCheckBox(SEPERATOR);
     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
 
 
     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
-    $this->AddRegex   ("Regex",     _("Display acls matching"),"Not implemented yet" , true);
+    $this->AddRegex   ("Regex",     _("Display acls matching"),"*" , true);
   }
 
 
   function GenHeader()
   {
-    /* Prepare departments,
+     /* Prepare departments,
        which are shown in the listbox on top of the listbox
      */
     $options= "";
-    foreach ($this->config->idepartments as $key => $value){
-      if ($this->selectedBase == $key){
-        $options.= "<option selected='selected' value='$key'>$value</option>";
-      } else {
-        $options.= "<option value='$key'>$value</option>";
+    $Copy_Paste = "";
+
+    /* Get all departments within this subtree */
+    $ui= get_userinfo();
+    $first = "";
+    $found = FALSE;
+    $base = $this->config->current['BASE'];
+    $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", "acl", $base,
+                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
+
+    /* Load possible departments */
+    $ui     = get_userinfo();
+    $tdeps  = $ui->get_module_departments("acl");
+    $ids    = $this->config->idepartments;
+    foreach($deps as $dep){
+      if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
+
+        /* Keep first base dn in mind, we could need this
+         *  info if no valid base was found
+         */
+        if(empty($first)) {
+          $first = $dep['dn'];
+        }
+  
+        $value = $ids[$dep['dn']];
+        if ($this->selectedBase == $dep['dn']){
+          $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
+        } else {
+          $options.= "<option value='".$dep['dn']."'>$value</option>";
+        }
       }
     }
 
-    /* Create header with selected base */
-    $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
-      " <input class='center' type='image' src='images/list_root.png' align='middle' 
-      title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
-      " <input class='center' type='image' align='middle' src='images/list_back.png' 
-      title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;".
-      " <input class='center' type='image' align='middle' src='images/list_home.png' 
-      title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;".
-      " <input class='center' type='image' src='images/list_reload.png' align='middle' 
-      title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
-      " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
-    $listhead .= $this->get_snapshot_header($this->selectedBase);
-    $listhead .=  
+    /* The currently used base is not visible with your acl setup.
+     * Set base to first useable base.
+     */
+    if(!$found){
+      $this->selectedBase = $first;
+    }
+
+    /* Allow copy & paste for roles */ 
+    $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"acl");
+    $acl      = $ui->get_permissions($this->selectedBase,"acl/acl");
+
+    /* Add default header */
+    $listhead = MultiSelectWindow::get_default_header();
+
+    /* Get copy & paste icon */
+    $Copy_Paste ="";
+    if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
+      $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
+      $addsep = true;
+    }
+
+    /* Add snapshot icons */
+    if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+      $listhead .= $this->get_snapshot_header($this->selectedBase);
+      $add_sep = true;
+    }
+
+    if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"acl/acl"))){
+      $add_sep = true;
+      $listhead .= "<input class='center' type='image' align='middle' src='images/list_new_acl_role.png'
+        name='new_acl_role'     alt='"._("New acl role")."' title='"._("New acl role")."'>&nbsp;";
+    }
+
+    $listhead .= $Copy_Paste. 
       _("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;".
@@ -106,20 +151,69 @@ class divListACL extends MultiSelectWindow
 
   function setEntries($list)
   {
-    $list_left_icon = "<img src='images/select_acl.png' alt='"._("Acl")."'>";
-    $editlink       = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
     foreach($list as $key => $acl_entry){
 
-      $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
-        name='acl_edit_%KEY%' title='"._("Edit system")."'>";
-      $action.= $this->GetSnapShotActions($acl_entry['dn']);
-      $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
-        name='acl_del_%KEY%' title='"._("Delete system")."'>";
+      /* Get copy & paste icon */
+      $acl        = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
+      $acl_all    = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
+      $action     = "";
+
+      if(in_array("gosaRole",$acl_entry['objectClass'])){
+
+        /* Role handling */
+        $editlink       = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=list_edit_role'>%s</a>";
+        $list_left_icon = "<img src='images/select_acl_role.png' alt='"._("Role")."'>";
+        $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
+
+        if(isset($acl_entry['description'][0])){
+          $cn .= "&nbsp;[".$acl_entry['description'][0]."]";
+        }
+
+        /* Add copy & paste handler */
+        if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
+          $action.= "<input class='center' type='image'
+            src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
+          $action.= "<input class='center' type='image'
+            src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
+        }
+
+        /* Add actions depending on acls */
+        if(preg_match("/r/", $acl)){
+          $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
+            name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
+        }
+
+        /* Add snapshot functionality */
+        if(preg_match("/(c.*w|w.*c)/", $acl_all)){
+          $action.= $this->GetSnapShotActions($acl_entry['dn']);
+        }
+
+        if(preg_match("/d/", $acl)){
+          $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
+            name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
+        }
+      }else{
+
+        /* Acl handling */
+        $editlink       = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=list_edit_entry'>%s</a>";
+        $list_left_icon = "<img src='images/select_acl.png' alt='"._("Acl")."'>";
+        $cn = htmlentities(utf8_decode($acl_entry['dn'])); 
+
+        /* Add actions depending on acls */
+        if(preg_match("/r/", $acl)){
+          $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
+            name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
+        }
+        if(preg_match("/d/", $acl)){
+          $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
+            name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
+        }
+      }
 
       $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
-      $field2 = array("string" => sprintf($editlink,$key,htmlentities(utf8_decode($acl_entry['dn'])))."&nbsp;","attach" => "");
-      $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:center;width:80px;border-right:0px;'");
+      $field2 = array("string" => sprintf($editlink,$key,$cn)."&nbsp;","attach" => "");
+      $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
       $this->AddElement(array($field1,$field2,$field3));
     }
   }
@@ -139,13 +233,7 @@ class divListACL extends MultiSelectWindow
   /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
   function set_filter_objectclasses()
   { 
-    #FIXME This should be created dynamically 
-    $this->gosaAccount = true;
-    $this->AddCheckBox("gosaAccount",     _("Select to display users"),       _("Display user")       , true);
-    $this->gosaDepartment = true;
-    $this->AddCheckBox("gosaDepartment",  _("Select to display departments"), _("Display departments"), true);
   }
-
   
   /* Return objectClass names used in filter part */  
   function get_filter_objectclasses()
@@ -153,6 +241,28 @@ class divListACL extends MultiSelectWindow
     return(array("gosaAccount","gosaDepartment"));
   }
 
+  
+  /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
+          "plDescription" => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles")."&nbsp;-&nbsp;("._("Access control list").")",
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("acl" => array("description"  => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
+                                                          "objectClass"  => array("gosaAcl","gosaRole"))),
+          "plProvidedAcls"=> array(
+            "cn"          => _("Role name"),
+            "description" => _("Role description"))
+
+          ));
+  }
+
+
+
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>