Code

Updated department dialog.
[gosa.git] / gosa-core / plugins / admin / departments / class_divListDepartment.inc
index b1f642dbf1edccab4eb653baa3f272c9323de1be..469b0163bc93a34d4c6c0f1d270874bcc1686db4 100644 (file)
@@ -1,4 +1,24 @@
 <?php
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id$$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 class divListDepartment extends MultiSelectWindow
 {
@@ -30,7 +50,6 @@ 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 number of departments, you might prefer the range selectors on top of the department list."));
   
     /* Disable buttonsm */
     $this->EnableCloseButton(false);
@@ -39,7 +58,7 @@ class divListDepartment extends MultiSelectWindow
 
 
    /* Toggle all selected / deselected */
-    $chk = "<input type='checkbox' id='select_all' name='select_all'
+    $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
                onClick='toggle_all_(\"^item_selected_[a-zA-Z0-9\\/\=]*$\",\"select_all\");' >";
 
     /* set Page header */
@@ -50,7 +69,7 @@ class divListDepartment extends MultiSelectWindow
 
 
     /* Add SubSearch checkbox */    
-    $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
+    $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
 
     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
     $this->AddRegex   ("Regex",     _("Regular expression for matching department names"), "*" , true);
@@ -116,28 +135,55 @@ class divListDepartment extends MultiSelectWindow
 
     /* Generate list head */
     $ui = get_userinfo();
-    $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/department");
       
     /* Add default header */
     $listhead = MultiSelectWindow::get_default_header();
 
     $listhead .=  
       " "._("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
-      " <input class='center' type='image' src='images/list_submit.png' align='middle' ".
+      " <input class='center' type='image' src='images/lists/submit.png' align='middle' ".
       "   title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
 
     /* Create Layers menu */
     $s  = ".|"._("Actions")."|\n";
-    $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
-      "&nbsp;"._("Create")."|\n";
 
     /* Append create options */
-    if(preg_match("/c/",$acl)) {
-      $s.= "...|<input class='center' type='image' src='images/list_new_department' alt=''>".
-        "&nbsp;"._("Department")."|dep_new|\n";
+    $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
+      "&nbsp;"._("Create")."|\n";
+
+    if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/department"))) {
+      $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
+        "&nbsp;"._("Department")."&nbsp;(ou)|dep_new_ou|\n";
+
     }
+
+    if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/organization"))) {
+      $s.= "...|<input class='center' type='image' src='plugins/departments/images/organization.png' alt=''>".
+        "&nbsp;"._("Organization")."&nbsp;(o)|dep_new_o|\n";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/country"))) {
+      $s.= "...|<input class='center' type='image' src='plugins/departments/images/country.png' alt=''>".
+        "&nbsp;"._("Country")."&nbsp;(c)"."|dep_new_c|\n";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/locality"))) {
+      $s.= "...|<input class='center' type='image' src='plugins/departments/images/locality.png' alt=''>".
+        "&nbsp;"._("Locality")."&nbsp;(l)|dep_new_l|\n";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/alias"))) {
+      $s.= "...|<input class='center' type='image' src='plugins/departments/images/department_alias.png' alt=''>".
+        "&nbsp;"._("Alias")."|dep_new_alias|\n";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/referal"))) {
+      $s.= "...|<input class='center' type='image' src='plugins/departments/images/department_referal.png' alt=''>".
+        "&nbsp;"._("Referal")."|dep_new_referal|\n";
+    }
+
     $s.= "..|---|\n";
-    $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
+    $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
 
 
@@ -155,52 +201,114 @@ class divListDepartment extends MultiSelectWindow
   {
     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
 
+    /* Possible department types
+     */
+    $types['country']            = array("ACL" => "country",      "ATTR" => "c",
+        "TITLE"     => _("Department"),
+        "IMG_FULL"  => "plugins/departments/images/country.png", 
+        "IMG"       => "plugins/departments/images/country.png", "ABBR" => "c");
+    $types['locality']           = array("ACL" => "locality",     "ATTR" => "l",
+        "TITLE"     => _("Department"),
+        "IMG"       => "plugins/departments/images/locality.png", "ABBR" => "l");
+    $types['organizationalUnit'] = array("ACL" => "department",   "ATTR" => "ou",
+        "TITLE"     => _("Department"),
+        "IMG_FULL"  => "images/lists/folder-full.png", 
+        "IMG"       => "images/lists/folder.png", "ABBR" => "ou");
+    $types['organization']       = array("ACL" => "organization", "ATTR" => "o",
+        "TITLE"     => _("Department"),
+        "IMG"       => "plugins/departments/images/organization.png", "ABBR" => "o");
+    $types['Alias??']            = array("ACL" => "alias"     ,    "ATTR" => "alias?",
+        "TITLE"     => _("Department"),
+        "IMG"       => "plugins/departments/images/department_alias.png", "ABBR" => "alias");
+    $types['Referal??']          = array("ACL" => "referal",       "ATTR" => "referal?",
+        "TITLE"     => _("Department"),
+        "IMG"       => "plugins/departments/images/department_referal.png", "ABBR" => "referal");
+
+    $this->departments = $list;
+
     $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")."'>";
+      /* Detect department type
+       */
+      $dep_data = array();
+      foreach($types as $type => $data){
+        if(in_array($type,$val['objectClass'])){
+          $dep_data  = $data;
+          break;
+        }
       }
-
-      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")."'>";
+    
+      /* Warn if there was an unknown department type found 
+       */ 
+      if(!count($dep_data)) {
+        trigger_error("Unknown department type given. Skipped '".$val['dn']."'.");
+        continue;
       }
 
-      if(!isset($this->config->departments[trim($key)])){
-        $this->config->departments[trim($key)]="";
+      /* Get permissions 
+       */
+      $acl = $ui->get_permissions($val['dn'],"department/".$dep_data['ACL']);
+      $acl_all = $ui->has_complete_category_acls($val['dn'],"department");
+
+      /* Create actions 
+       */
+      $actions.= "<input class='center' type='image' src='images/lists/edit.png'
+        alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
+      if(preg_match("/d/",$acl)){
+        $actions.= "<input class='center' type='image' src='images/lists/trash.png'
+          alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
       }
 
-      /* check if this department contains sub-departments
+      /* Check if this department contains sub-departments
          Display different image in this case
        */
-      $non_empty="";
-      $nkey= normalizePreg($key);
-      foreach($this->config->departments as $keyd=>$vald ){
-        if(preg_match('/$nkey\/.*/',$keyd)){
-          $non_empty="full";
+      $sub_folders= FALSE;
+      foreach($this->config->departments as $keyd){
+        if(preg_match("/,".normalizePreg($val['dn'])."$/",$keyd)){
+          $sub_folders = TRUE;
         }
       }
 
-      $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($this->config->departments[$key]));
+      /* Create entry name 
+       */      
+      $name = $val[$dep_data['ATTR']][0];
+      if(isset($val['description'])){
+        $name .=  " - [".$val["description"][0]."]";
+      }
+
+      /* Create title
+       */
+      $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']));
 
-      if($val == "."){
+      /* Create checkboxes infront of the entry 
+       */
+      if($name == "."){
         $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)."'>" ,
+        $field01 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$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;'");
+      /* Create image 
+       */
+      if($sub_folders){
+        $img =  "<img src='".$dep_data['IMG_FULL']."' class='center' title='".$dep_data['TITLE']."'>";
+      }else{
+        $img =  "<img src='".$dep_data['IMG']."' class='center' title='".$dep_data['TITLE']."'>";
+      }
+     
+      /* Append data to the listing 
+       */
+      $field0 = array("string" => $img, "attach" => "style='text-align:center;width:20px;'");
+      $field1 = array("string" => sprintf($linkopen,$key,$name), 
+          "attach" => "style='' title='".$title."'");
+      $field2 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
+          "attach" => "style='width:60px;border-right:0px;text-align:right;'");
 
       $this->AddElement( array($field01,$field0,$field1,$field2));
     }
@@ -208,7 +316,7 @@ class divListDepartment extends MultiSelectWindow
     /* Create summary string for list footer */
     $num_deps=count($list);
     $num_dep_str = _("Number of listed departments");
-    $str = "<img class='center' src='images/folder.png'
+    $str = "<img class='center' src='images/lists/folder.png'
               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
     $this->set_List_Bottom_Info($str);