Code

Added some logging
[gosa.git] / plugins / admin / departments / class_divListDepartment.inc
index 7ea33e77518d3c22c64363495e2268cea1fed25c..c3a59151906c925885b8f3cc8d0416205c2cd143 100755 (executable)
@@ -36,7 +36,14 @@ class divListDepartment extends MultiSelectWindow
     $this->EnableCloseButton(false);
     $this->EnableSaveButton (false);
 
+
+
+   /* Toggle all selected / deselected */
+    $chk = "<input type='checkbox' id='select_all' name='select_all'
+               onClick='toggle_all_(\"^item_selected_[a-zA-Z0-9\=]*$\",\"select_all\");' >";
+
     /* set Page header */
+    $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
     $this->AddHeader(array("string"=>_("Department name"), "attach" => "style=''"));
     $this->AddHeader(array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'"));
@@ -58,43 +65,62 @@ class divListDepartment extends MultiSelectWindow
     $options= "";
 
     /* Get all departments within this subtree */
+    $ui= get_userinfo();
+    $first = "";
+    $found = FALSE;
     $base = $this->config->current['BASE'];
-    $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
-                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
+
+    /* Add base */
+    $tmp = array();
+    $tmp[] = array("dn"=>$this->config->current['BASE']);
+    $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
+                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
+
+    $deps = array();
+    foreach($tmp as $tm){
+      $deps[$tm['dn']] = $tm['dn'];
+    }
 
     /* Load possible departments */
     $ui= get_userinfo();
     $tdeps= $ui->get_module_departments("department");
-
     $ids = $this->config->idepartments;
+    $first = "";
+    $found = FALSE;
+    foreach($ids as $dep => $name){
+      if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
+
+        /* Keep first base dn in mind, we could need this
+         *  info if no valid base was found
+         */
+        if(empty($first)) {
+          $first = $dep['dn'];
+        }
 
-    foreach($deps as $dep){
-      if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
-
-        $value = $ids[$dep['dn']];
-        if ($this->selectedBase == $dep['dn']){
-          $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
+        $value = $ids[$dep];
+        if ($this->selectedBase == $dep){
+          $found = TRUE;
+          $options.= "<option selected='selected' value='".$dep."'>$value</option>";
         } else {
-          $options.= "<option value='".$dep['dn']."'>$value</option>";
+          $options.= "<option value='".$dep."'>$value</option>";
         }
       }
     }
 
+    /* The currently used base is not visible with your acl setup.
+     * Set base to first useable base.
+     */
+    if(!$found){
+      $this->selectedBase = $first;
+    }
 
     /* Generate list head */
     $ui = get_userinfo();
     $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/department");
-
-    $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
-      " <input type='image' class='center' src='images/list_root.png' align='middle' ".
-      "   title='"._("Go to root department")."' name='dep_root' alt='".       _("Root")."'>&nbsp;".
-      " <input type='image' class='center' src='images/list_up.png' align='middle' ".
-      "   title='"._("Go up one department")."' name='dep_back' alt='"._("Up").  "'>&nbsp;".
-      " <input type='image' class='center' src='images/list_home.png' align='middle' ".
-      "   title='"._("Go to users home department")."' name='dep_home' alt='". _("Home")."'>&nbsp;".
-      " <input class='center' type='image' src='images/list_reload.png' align='middle' ".
-      "   title='"._("Reload list")."' name='submit_department' alt='".      _("Submit")."'>&nbsp;";
       
+    /* Add default header */
+    $listhead = MultiSelectWindow::get_default_header();
+
     if(preg_match("/c/",$acl)){
       $listhead .=  " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
         " <input class='center' type='image' src='images/list_new_department.png' ".
@@ -102,12 +128,17 @@ class divListDepartment extends MultiSelectWindow
     }
   
 
-    $listhead .= $acl." <img class='center' src='images/list_seperator.png' align='middle' ".
+    $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' ".
       " alt='' height='16' width='1'>&nbsp;".
       " "._("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 departments")."' alt='"._("Remove departments")."' name='remove_multiple_departments'>&nbsp;";
+
+    $listhead .="</div>";;
 
     $this->SetListHeader($listhead);
   }
@@ -151,12 +182,22 @@ class divListDepartment extends MultiSelectWindow
       }
 
       $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($this->config->departments[$key]));
+
+      if($val == "."){
+        $field01 = array("string" => "&nbsp;",
+            "attach" => "style='width:20px;'");
+      }else{
+        $field01 = array("string" => "<input type='checkbox' id='item_selected_".base64_encode($key)."' 
+            name='item_selected_".base64_encode($key)."'>" ,
+            "attach" => "style='width:20px;'");
+      }
+
       $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
       $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
       $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align:
           right;'");
 
-      $this->AddElement( array($field0,$field1,$field2));
+      $this->AddElement( array($field01,$field0,$field1,$field2));
     }
   }