Code

Added some logging
[gosa.git] / plugins / admin / departments / class_divListDepartment.inc
index 94ff8d2c4b9a21f38a28a486fe1a071721ddf317..c3a59151906c925885b8f3cc8d0416205c2cd143 100755 (executable)
@@ -18,7 +18,7 @@ class divListDepartment extends MultiSelectWindow
 
   function divListDepartment ($config,$parent)
   {
-    MultiSelectWindow::MultiSelectWindow($config,"Department");
+    MultiSelectWindow::MultiSelectWindow($config, "Department", "department");
     
     $this->parent       = $parent;
     $this->ui           = get_userinfo();
@@ -30,14 +30,20 @@ class divListDepartment extends MultiSelectWindow
 
     /* Result page will look like a headpage */
     $this->SetHeadpageMode();
-    $this->SetInformation(_("This menu allows you to create, delete and edit selected departments. ".
-                            "Having a large size of departments, you might prefer the range selectors on   top of the department list."));
+    $this->SetInformation(_("This menu allows you to create, delete and edit selected departments. Having a large number of departments, you might prefer the range selectors on top of the department list."));
   
     /* Disable buttonsm */
     $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;'"));
@@ -47,7 +53,7 @@ class divListDepartment extends MultiSelectWindow
     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
 
     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
-    $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
+    $this->AddRegex   ("Regex",     _("Regular expression for matching department names"), "*" , true);
   }
 
 
@@ -55,28 +61,84 @@ class divListDepartment extends MultiSelectWindow
   {
     /* 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>";
+
+    /* Get all departments within this subtree */
+    $ui= get_userinfo();
+    $first = "";
+    $found = FALSE;
+    $base = $this->config->current['BASE'];
+
+    /* 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'];
+        }
+
+        $value = $ids[$dep];
+        if ($this->selectedBase == $dep){
+          $found = TRUE;
+          $options.= "<option selected='selected' value='".$dep."'>$value</option>";
+        } else {
+          $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 */
-      $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;".
-        " <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' align='middle' alt='"._("Create new department")."' name='dep_new'>&nbsp; ".
-        " <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>";
+    $ui = get_userinfo();
+    $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/department");
+      
+    /* 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' ".
+        "   align='middle' alt='"._("Create new department")."' name='dep_new'>&nbsp; ";
+    }
+  
+
+    $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;";
+
+    /* 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);
   }
@@ -89,14 +151,24 @@ class divListDepartment extends MultiSelectWindow
 
   function setEntries($list)
   {
-    $actions= "<input class='center' type='image' src='images/edit.png'
-      alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
-    $actions.= "<input class='center' type='image' src='images/edittrash.png'
-      alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
-
     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
 
+    $ui = get_userinfo();
     foreach($list as $key => $val) {
+
+      $actions= "";      
+
+      $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department");
+      if(preg_match("/r/",$acl)){
+        $actions.= "<input class='center' type='image' src='images/edit.png'
+          alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
+      }
+
+      if(preg_match("/c/",$acl)){
+        $actions.= "<input class='center' type='image' src='images/edittrash.png'
+          alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
+      }
+
       if(!isset($this->config->departments[trim($key)])){
         $this->config->departments[trim($key)]="";
       }
@@ -109,20 +181,29 @@ class divListDepartment extends MultiSelectWindow
         }
       }
 
-      $title = $this->config->departments[$key];
-      $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-
-          align:center;width:20px;'");
+      $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));
     }
   }
 
   function Save()
   {
-    MultiSelectWindow :: Save();  
+    MultiSelectWindow::Save();
   }
 
   function save_object()