Code

Updated list handling
[gosa.git] / gosa-core / include / class_MultiSelectWindow.inc
index 38e1557b757776ff1033815509ee35d9edb87b99..9c9bd5071763836acd638b6201d0f0a983b95fd5 100644 (file)
@@ -529,9 +529,12 @@ class MultiSelectWindow{
       }
     }
 
-    /* Save base selection from headpage selectbox*/
+    /* Save base selection from headpage selectbox */
     if(isset($_POST['CurrentMainBase'])){
-      $this->selectedBase = $_POST['CurrentMainBase'];
+      $this->selectedBase = get_post('CurrentMainBase');
+      session::global_set("CurrentMainBase", $this->selectedBase);
+    } else {
+      $this->selectedBase= session::global_get("CurrentMainBase");
     }
 
     /* Homebutton is posted */
@@ -645,7 +648,7 @@ class MultiSelectWindow{
                }
 
     /* Save currenlty selected base in session */
-    session::set("CurrentMainBase",$this->selectedBase);
+    session::global_set("CurrentMainBase",$this->selectedBase);
        }
 
 
@@ -655,11 +658,16 @@ class MultiSelectWindow{
                $this->DepartmentsAdded = true;
     $this->Added_Departments = array();
     $this->departments = array();
+
+    if(isset($this->Regex)){
+      $this->base_selection_regex = $this->Regex;
+    }
+
                $linkopen = "<a href='?plug=".$_GET['plug']."&amp;post_id=".$this->post_id."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
     $types = departmentManagement::get_support_departments();
     $ui = get_userinfo();
     $module_deps = $ui->get_module_departments($this->module);
-
+    $found_deps = array();
 
                /* check for a valid base */
                if(!$base){
@@ -672,18 +680,17 @@ class MultiSelectWindow{
 
                /* Get all departments within this subtree */
     $s_filter = "";
-    $s_attrs  = array("description");
-    $s_acls   = array();
+    $s_attrs  = array("description","objectClass");
+    $s_acls   = $this->module;
     foreach($types as $name => $data){
-      $s_filter.= "(&(objectClass=".$data['OC'].")(".$data['ATTR']."=".$this->base_selection_regex."))";
+      $s_filter.= "(&(objectClass=gosaDepartment)(objectClass=".$data['OC'].")(".$data['ATTR']."=".$this->base_selection_regex."))";
       $s_attrs[]= $data['ATTR']; 
-      $s_acls[] = "department/".$data['ACL'];
     }
 
     $tmp = get_list("(|".$s_filter.")",$s_acls,$this->selectedBase,$s_attrs,GL_NONE);
     foreach($tmp as $attrs){
       foreach($types as $name => $data){
-        if(isset($attrs[$data['ATTR']][0])){
+        if(in_array($data['OC'],$attrs['objectClass']) && isset($attrs[$data['ATTR']][0])){
           $attrs['NAME'] = $attrs[$data['ATTR']][0];
           $attrs['TYPE'] = $data;
           $name = $attrs['NAME']." ".$attrs['dn'];
@@ -693,29 +700,17 @@ class MultiSelectWindow{
         }
       }
     }
-    uksort($departments, 'strnatcasecmp');
 
     /* Detect allowed departments 
      */
     $deps = array_intersect($found_deps,$module_deps);
+    uksort($deps, 'strnatcasecmp');
     $key = 0;
     foreach($deps as $name => $dn){
       $key ++;
       $val = $departments[$name];
       $this->departments[$key] = $val;
-    
-      /* Check if this department contains sub-departments
-         Display different image in this case
-       */
-      $img = $val['TYPE']['IMG'];
-#      foreach($this->config->departments as $keyd){
-#        if(preg_match("/,".normalizePreg($val['dn'])."$/",$keyd)){
-#          $img = $val['TYPE']['IMG_FULL'];
-#        }
-#     }
-
-  
-      $img = "<image src='".$img."' class='center'>";
+      $img = "<image src='".$val['TYPE']['IMG']."' class='center'>";
 
                        /* Add spacer cols to divlist 
        */
@@ -757,45 +752,36 @@ class MultiSelectWindow{
 
   function create_department_list($modules)
   { 
-     /* Load possible departments */
+    $departments = array();
     $ui= get_userinfo();
     $first = "";
     $found = FALSE;
+    $options ="";
 
-    if(!is_array($modules)){
-      $modules = array($modules);
-    }
-
-    $department = $departments = array();
     $ids = $this->config->idepartments;
-    foreach($modules as $module){
-      $d = $ui->get_module_departments($module);
-
-      foreach($ids as $department => $desc){
-        if(in_array($department,$d)){
-          $departments[$department] = $department;
-        }
-      }
+    $d   = $ui->get_module_departments($modules);
+    $k_ids = array_keys($ids);
+    $deps = array_intersect($d,$k_ids);
+    foreach($k_ids as $department){
+      $departments[$department] = $ids[$department];
     }
 
-    $first = "";
-    $found = FALSE;
-    $options ="";
-    foreach($departments as $dep => $name){
+    foreach($departments as $value => $name){
 
       /* Keep first base dn in mind, we could need this
        *  info if no valid base was found
        */
       if(empty($first)) {
-        $first = $dep['dn'];
+        $first = $value;
       }
 
-      $value = $ids[$dep];
-      if ($this->selectedBase == $dep){
+
+      $v_value = htmlentities($value,ENT_QUOTES);
+      if ($this->selectedBase == $value){
         $found = TRUE;
-        $options.= "<option selected='selected' value='".$dep."'>$value</option>";
+        $options.= "<option selected='selected' value=\"".$v_value."\">$name</option>";
       } else {
-        $options.= "<option value='".$dep."'>$value</option>";
+        $options.= "<option value=\"".$v_value."\">$name</option>";
       }
     }