Code

Updated role management
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 3 Jul 2009 09:39:47 +0000 (09:39 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 3 Jul 2009 09:39:47 +0000 (09:39 +0000)
-Added member/occupant selection.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13880 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/roleManagement/admin/roleManagement/class_occupantSelect.inc
gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc
gosa-plugins/roleManagement/admin/roleManagement/occupantSelect.tpl

index 2d5856e4022504e848b824996a7667170ff1bb73..7fc690e9f434c809d68e0f9b83fc7776c2497643 100644 (file)
@@ -26,17 +26,137 @@ class occupantSelect  extends plugin {
     $this->config = $config;
     $this->dn = $dn;
     $this->parent = $parent;
+    $this->skipEntries = $parent->getOccupants();
+
+    /* Get global filter config */
+    if (!session::is_set("roleAddOccupantFilter")){
+      $ui= get_userinfo();
+      $base= get_base_from_people($ui->dn);
+      $roleAddOccupantFilter= array(  
+          "dselect"       => $base,
+          "subtrees"       => FALSE,
+          "regex"           => "*");
+      session::set("roleAddOccupantFilter", $roleAddOccupantFilter);
+    }
+
   }
   
 
   function execute()
   {
+    /* Save data */
+    $roleAddOccupantFilter= session::get("roleAddOccupantFilter");
+    if(isset($_POST['occupantSearched'])){
+
+      $roleAddOccupantFilter['subtrees'] = false;
+      if(isset($_POST['subtrees'])){
+        $roleAddOccupantFilter['subtrees'] = "checked";
+      }
+  
+      foreach( array("dselect", "regex") as $type){
+        if (isset($_POST[$type])){
+          $roleAddOccupantFilter[$type]= $_POST[$type];
+        }
+      }
+    }
+    if (isset($_GET['search'])){
+      $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
+      if ($s == "**"){
+        $s= "*";
+      }
+      $roleAddOccupantFilter['regex']= $s;
+    }
+    session::set("roleAddOccupantFilter", $roleAddOccupantFilter);
+
     $smarty = get_smarty();
+    $smarty->assign("search_image", get_template_path('images/lists/search.png'));
+    $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
+    $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
+    $smarty->assign("deplist", $this->config->idepartments);
+    $smarty->assign("alphabet", generate_alphabet());
+    $smarty->assign("hint", print_sizelimit_warning());
+    $smarty->assign("apply", apply_filter());
+    $smarty->assign("objects", $this->getObjects());
+    foreach( array("dselect", "regex", "subtrees") as $type){
+      $smarty->assign("$type", $roleAddOccupantFilter[$type]);
+    }
+    return($smarty->fetch(get_template_path("occupantSelect.tpl",TRUE, dirname(__FILE__))));
+  }
+
   
-    
+  function getObjects()
+  {
+
+    // Initialize variables 
+    $ldap = $this->config->get_ldap_link();
+    $roleAddOccupantFilter= session::get("roleAddOccupantFilter");
+    $regex  = $roleAddOccupantFilter['regex'];
+
+    // Detect the base to be use for ldap search
+    if($roleAddOccupantFilter['subtrees']){
+      $base =  $roleAddOccupantFilter['dselect'];
+    }else{
+      $base =  get_people_ou().$roleAddOccupantFilter['dselect'];
+    }
+
+    // Set search flags flat/subsearch 
+    $Get_list_flags = 0;
+    if($roleAddOccupantFilter['subtrees'] == "checked"){
+      $Get_list_flags |= GL_SUBSEARCH;
+    }
+
+    // Search for matching user objects.
+    $filter = "(&(objectClass=gosaAccount)(!(uid=*$))(|(uid=$regex)(cn=$regex)))";
+    $res    = get_list($filter, "users/user"  , $base,
+        array("description", "objectClass", "sn", "givenName", "uid","cn"),$Get_list_flags);
+
+    // Collect data.
+    $this->objects = array(); 
+    foreach($res as $attrs){
+
+      // Skip entries which are already part of our role 
+      if(in_array($attrs['dn'], $this->skipEntries)) continue;
+      $name = $attrs['cn'][0];
+      $dn = $attrs['dn'];
+      if (isset($attrs["description"][0])){
+        $name .= " [".$attrs["description"][0]."]";
+      }
   
-    return($smarty->fetch(get_template_path("occupantSelect.tpl",TRUE, dirname(__FILE__))));
+      $entry = array();
+      $entry['attrs'] = $attrs;
+      $entry['name'] = $name;
+      $entry['dn'] = $dn;
+      $this->objects[] = $entry; 
+    }
+    uksort ($this->objects, 'strnatcasecmp');
+    reset ($this->objects);
+
+    // Create HTML content 
+    $temp = "";
+    foreach ($this->objects as $key => $value){
+      $temp.= "
+        <option 
+            title='".addslashes($value['dn'])."' 
+            value='$key' class='select' 
+            style=\"background-image:url('plugins/generic/images/head.png');
+      \">".$value['name']."</option>\n";
+    }
+    return ($temp);
   }
+
+  function save()
+  {
+    $ret = array();
+    if(isset($_POST['objects'])){
+      $objects = $_POST['objects'];
+      foreach($objects as $id){
+        $ret[] = $this->objects[$id];
+      }
+    }
+    return($ret); 
+  } 
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index 1892f8115e5f6f51928159aa6445b81abf949203..ee30124ec0ae3e9379ae3c1a037b4c41cf38bbb8 100644 (file)
@@ -28,7 +28,6 @@ class roleGeneric extends plugin {
   var $description ="";
   var $telephoneNumber = "";
   var $facsimileTelephoneNumber = "";
-  var $roleOccupant = array();
 
   // The objects base 
   var $base = "";
@@ -41,6 +40,12 @@ class roleGeneric extends plugin {
   // The object classes written by this plugin
   var $objectclasses = array("top","organizationalRole");
 
+  // The list of occupants  ([dn])
+  var $roleOccupant = array();
+  
+  // The roleOccupant cache, dn=>attrs
+  var $roleOccCache = array();
+
   // A list of attributes managed by this plugin
   var $attributes = array("cn","description",
     "telephoneNumber","facsimileTelephoneNumber","roleOccupant");
@@ -52,6 +57,14 @@ class roleGeneric extends plugin {
     plugin::plugin($config,$dn);
     $this->is_account = TRUE;
 
+    // Initialize list of occupants
+    $this->roleOccupant = array();
+    if(isset($this->attrs['roleOccupant'])){
+      for($i=0;$i<$this->attrs['roleOccupant']['count']; $i++){
+        $this->roleOccupant[] = $this->attrs['roleOccupant'][$i];
+      }
+    }
+
     // Detect the objects base
     if ($this->dn == "new"){
       $this->base = session::get('CurrentMainBase');
@@ -63,9 +76,39 @@ class roleGeneric extends plugin {
     $this->orig_base = $this->base;
     $this->orig_dn = $dn;
     $this->orig_cn = $this->cn;
+
+    // Reload the occupant cache. 
+    $this->reload();
   }
 
 
+  /* Keep occupant cache up to date. 
+   * Else, we may have entries we can't display.
+   */
+  function reload()
+  {
+    // Entries can't be added twice. 
+    $attrs = array("description", "objectClass", "uid","cn");
+    $this->roleOccupant = array_unique($this->roleOccupant);
+    $this->roleOccupant = array_values($this->roleOccupant);
+  
+    $ldap = $this->config->get_ldap_link();
+    foreach($this->roleOccupant as $dn){
+      if(!isset($this->roleOccCache[$dn])){
+        if($ldap->dn_exists($dn)){
+          $ldap->cat($dn, $attrs);
+          $this->roleOccCache[$dn] = $ldap->fetch();
+        }
+      }
+    }
+
+  }
+  
+
+  function getOccupants(){
+    return($this->roleOccupant);
+  }
+
   /* Generate HTML output of this plugin.
    */
   function execute()
@@ -81,6 +124,29 @@ class roleGeneric extends plugin {
     if(isset($_POST['edit_membership']) && !$this->dialog instanceOf plugin){
       $this->dialog = new occupantSelect($this->config,$this->dn,$this);
     }
+    if(isset($_POST['delete_membership']) && !$this->dialog instanceOf plugin){
+      if(isset($_POST['members'])){
+        foreach($_POST['members'] as $id){
+          if(isset($this->roleOccupant[$id])){
+            unset($this->roleOccupant[$id]);
+          }
+        }
+        $this->reload();
+      }
+    }
+
+    if(isset($_POST['add_object_cancel']) && $this->dialog instanceOf plugin){
+      $this->dialog = NULL;
+    }
+    if(isset($_POST['add_object_finish']) && $this->dialog instanceOf plugin){
+      $ret = $this->dialog->save();
+      foreach($ret as $key => $entry){
+        $this->roleOccupant[] = $entry['dn'];
+        $this->roleOccCache[$entry['dn']] = $entry['attrs'];
+      }
+      $this->reload();
+      $this->dialog = NULL;
+    }
 
     if($this->dialog instanceOf plugin){
       $this->dialog->save_object();
@@ -88,6 +154,9 @@ class roleGeneric extends plugin {
     }
 
 
+    /***************
+     * Template handling
+     ***************/
 
     // Get smarty instance and assign required variables.
     $smarty = get_smarty();
@@ -144,13 +213,19 @@ class roleGeneric extends plugin {
   function convert_list()
   {
     $temp= "";
-    foreach ($this->roleOccupant as $key => $value){
-      $temp.= "
-        <option title='".addslashes( $key)."' 
-        value=\"$key\" class=\"select\" 
-        >".$value['text']."</option>\n";
+    $icon = " style=\"background-image:url('plugins/generic/images/head.png');\" ";
+    foreach ($this->roleOccupant as $key => $dn){
+      if(isset($this->roleOccCache[$dn])){
+        $entry = $this->roleOccCache[$dn];
+        $name = $entry['cn']['0'];
+        if(isset($entry['description'][0])){
+          $name .= " [".$entry['description'][0]."]";
+        }
+      }else{
+        $name = _("Unknown")."&nbsp;".$dn;
+      }
+      $temp.= "<option {$icon} title='{$dn}' value='$key' class='select'>{$name}</option>\n";
     }
-
     return ($temp);
   }
 
index 0e5ccffbcf8fb4d697caacd2214a8818dfed89a8..c34e2973194ba8e69b4a8fae6f91a7b1d5b6fc54 100644 (file)
@@ -1,7 +1,49 @@
+<table summary="" style="width:100%; vertical-align:top; text-align:left;" cellpadding=4>
+<tr>
+  <td style="vertical-align:top; width:600px;">
+   <div class="contentboxh" style="height:20px;">
+    <p class="contentboxh" style="font-size:12px">
+     <b>{t}Select objects to add{/t} {$hint}</b>
+    </p>
+   </div>
+   <div class="contentboxb">
+    <p class="contentboxb" style="border-top:1px solid #B0B0B0;background-color:#F8F8F8">
+     <select style="width:600px; height:450px; margin-top:4px;" name="objects[]" size="15" multiple>
+      {$objects}
+     </select>
+     <input type=hidden name="edit_helper">
+    </p>
+   </div>
+  </td>
+  <td style="vertical-align:top;">
+   <div class="contentboxh" style="height:20px;">
+    <p class="contentboxh" style="font-size:12px"><img src="{$launchimage}" align="right" alt="[F]"><b>{t}Filters{/t}</b></p>
+   </div>
+   <div class="contentboxb">
+     <table summary="" style="width:100%;border-top:1px solid #B0B0B0; background-color:#F8F8F8">
+      {$alphabet}
+     </table>
+ <p class="contentboxb" style="border-top:1px solid #B0B0B0; background-color:#F8F8F8">
+    <input type=checkbox name="subtrees" value="1" {$subtrees} onClick="mainform.submit()" title="{t}Select to search within subtrees{/t}">{t}Search in subtrees{/t}<br>
+ </p>
+
+    <table summary="" width="100%" style="border-top:1px solid #B0B0B0;background-color:#F8F8F8"><tr><td width="50%"><img alt="" src="{$tree_image}" align=middle title="{t}Display objects of department{/t}">&nbsp;
+    <select name="dselect" size=1 onChange="mainform.submit()" title="{t}Choose the department the search will be based on{/t}">
+      {html_options options=$deplist selected=$dselect}
+    </select></td></tr></table>
+    <table summary="" width="100%" style="border-top:1px solid #B0B0B0;background-color:#F8F8F8"><tr><td style="width:18px"><img alt="" src="{$search_image}" align=middle title="{t}Display objects matching{/t}"></td>
+    <td><input type='text' name='regex' maxlength='20' style="width:99%" value='{$regex}' title='{t}Regular expression for matching object names{/t}' onChange="mainform.submit()"></td></tr></table>
+   {$apply}
+   </div>
+  </td>
+</tr>
+</table>
+
+<input type='hidden' value='1' name='occupantSearched'>
 
 <p class="plugbottom">
-       <input type=submit name="occupants_save" value="{msgPool type=addButton}">
-               &nbsp;
-       <input type=submit name="occupants_cancel" value="{msgPool type=cancelButton}">
+  <input type=submit name="add_object_finish" value="{msgPool type=addButton}">
+  &nbsp;
+  <input type=submit name="add_object_cancel" value="{msgPool type=cancelButton}">
 </p>