Code

Fixed FAI
[gosa.git] / plugins / admin / groups / class_groupManagement.inc
index a3fde2f34d85a6d546ae4534c1fc7b03c372a99b..f5c96f2e7566ab5ecefd9974430ff838c2493388 100644 (file)
@@ -123,7 +123,6 @@ class groupManagement extends plugin
       $s_action="open";
       $s_entry = base64_decode($_GET['dep_id']);
       $groupfilter['depselect']= "".$this->config->departments[trim($s_entry)];
-      $this->reload();
     }
 
     // Edit if
@@ -135,19 +134,16 @@ class groupManagement extends plugin
     /* Department changed? */
     if(isset($_POST['depselect']) && $_POST['depselect']){
       $groupfilter['depselect']= $_POST['depselect'];
-      $this->reload();
     }
 
     /* Homebutton is posted */
     if($s_action=="home"){
       $groupfilter['depselect']= (preg_replace("/^[^,]+,/","",$this->ui->dn));
       $groupfilter['depselect']= (preg_replace("/^[^,]+,/","",$groupfilter['depselect']));
-      $this->reload();
     }
 
     if($s_action=="root"){
       $groupfilter['depselect']=($this->config->current['BASE']);
-      $this->reload();
     }
 
     /* If Backbutton is Posted */
@@ -160,19 +156,13 @@ class groupManagement extends plugin
       }else{
         $groupfilter['depselect']= $this->config->departments["/"];
       }
-      $this->reload();
     }
     register_global("groupfilter", $groupfilter);
 
     $smarty= get_smarty();
 
     /* Prepare formular */
-    if (!isset($this->grouptab) &&
-        !isset($_POST['new_group']) &&
-        !isset($_POST['delete_group']) &&
-        !isset($_POST['select_group'])){
-      $this->reload();
-    }
+    $this->reload();
 
     /* Check for exeeded sizelimit */
     if (($message= check_sizelimit()) != ""){
@@ -383,16 +373,17 @@ class groupManagement extends plugin
     $mailimg  = "<img src='images/mailto.png'             alt='M'  title='"._("Mail")   ."'>";
     $sambaimg = "<img src='images/select_winstation.png'  alt='S'  title='"._("Samba")  ."'>";
     $applimg  = "<img src='images/select_application.png' alt='A'  title='"._("Application")."'>"; 
-    $phoneimg  = "<img src='images/select_phone.png'      alt='Ph' title='"._("Phone")  ."'>"; 
+    $phoneimg = "<img src='images/select_phone.png'      alt='Ph' title='"._("Phone")  ."'>"; 
+    $envimg   = "<img src='images/network.png'      alt='E' title='"._("Environment")  ."'>"; 
     // Space
     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
 
 
-    $divlist = new divlist();
+    $divlist = new divlist("groupstab");
     $divlist->SetHeader(array(
           array("string" => "&nbsp;"),
           array("string" => _("Groupname")." / "._("Department")),
-          array("string" => _("Properties"), "attach" => "style='width:100px;'"),
+          array("string" => _("Properties"), "attach" => "style='width:116px;'"),
           array("string" => _("Actions")    ,"attach" => "style='border:none'")
           ));
 
@@ -402,7 +393,20 @@ class groupManagement extends plugin
 
     foreach($this->departments as $key=> $val){
 
-      $field1 = array("string" => "<img src='images/folder.png' alt='department'>");
+      if(!isset($this->config->departments[trim($key)])){
+        $this->config->departments[trim($key)]="";
+      }
+
+      $non_empty="";
+      $keys= str_replace("/","\/",$key);
+      foreach($this->config->departments as $keyd=>$vald ){
+        if(preg_match("/".$keys."\/.*/",$keyd)){
+          $non_empty="full";
+        }
+      }
+
+
+      $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
       $field3 = array("string" => "&nbsp;");
       $field4 = array("string" => "&nbsp;","attach"=>"style='text-align:right;border:none'");
@@ -418,6 +422,7 @@ class groupManagement extends plugin
         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;   else $samba   = $empty;
         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;    else $appl    = $empty;
         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;   else $phone   = $empty;
+        if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;     else $enviro  = $empty;
       }else{
         $posix=$mail=$samba=$appl=$phone=$empty;
       }
@@ -431,7 +436,7 @@ class groupManagement extends plugin
       }      
       $field1 = array("string" => sprintf($userimg,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)),"attach"=>$title);
-      $field3 = array("string" => $posix."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone);  
+      $field3 = array("string" => $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone);  
       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions),"attach"=>"style='text-align:right;border:none;width:32px;'");
       
       $divlist->AddEntry(array($field1,$field2,$field3,$field4));    
@@ -440,7 +445,8 @@ class groupManagement extends plugin
     /* Show main page */
     $smarty->assign("grouplisthead", $listhead);
     $smarty->assign("grouplist", $divlist->DrawList());
-    $smarty->assign("search_image", get_template_path('images/search.png'));
+    $smarty->assign("searchg_image", get_template_path('images/search_group.png'));
+    $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
     $smarty->assign("tree_image", get_template_path('images/tree.png'));
     $smarty->assign("infoimage", get_template_path('images/info.png'));
     $smarty->assign("launchimage", get_template_path('images/launch.png'));
@@ -458,7 +464,8 @@ class groupManagement extends plugin
   }
 
 
-  function reload()
+
+  function reload2()
   {
     /* Get config */
     $groupfilter= get_global('groupfilter');
@@ -502,6 +509,125 @@ class groupManagement extends plugin
       }
       $filter.= ")))";
     }
+ /* Set filter depending on selection */
+    $sfilter= "";
+    if ($groupfilter['appgroups'] == "checked"){
+      $filter.= "(objectClass=gosaApplicationGroup)";
+    }
+    if ($this->config->current['SAMBAVERSION'] == 3){
+      if ($groupfilter['primarygroups'] != "checked"){
+        $sfilter= "(objectClass=sambaGroupMapping)";
+      } elseif ($groupfilter['sambagroups'] == "checked"){
+        $filter.= "(objectClass=sambaGroupMapping)";
+      }
+    }
+
+    if ($groupfilter['mailgroups'] == "checked"){
+      $filter.= "(objectClass=gosaMailAccount)";
+    }
+    if ($groupfilter['functionalgroups'] == "checked"){
+      $ldap->cd($base);
+      $ldap->set_size_limit($_SESSION['size_limit']);
+      $ldap->search("(&(cn=$regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))", array("cn",      "gidNumber", "description"));
+      $error2= $ldap->error;
+      while ($attrs= $ldap->fetch()){
+        if (!isset($primaries[$attrs['gidNumber'][0]])){
+          if (isset($attrs["description"][0])){
+            $this->grouplist[$attrs["dn"]]= $attrs["cn"][0]." [".
+              $attrs["description"][0]."]";
+          } else {
+            $this->grouplist[$attrs["dn"]]= $attrs["cn"][0];
+          }
+        }
+      }
+    }
+
+    /* Generate grouplist */
+    if ($filter != ""){
+      $filter= "(&(cn=$regex)(objectClass=posixGroup)(|$filter))";
+      if ($groupfilter['guser'] != ""){
+        $filter= "(&(|(memberUID=" . $groupfilter['guser'] . ")(cn=" . $groupfilter['guser'] . "))$filter)";
+      }
+    }
+    if ($groupfilter['subsearch'] != "checked"){
+      $res= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("cn", "description", "gidNumber"), TRUE);
+    } else {
+      $base= get_groups_ou().$base;
+     
+      $res= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("cn", "description", "gidNumber"), TRUE);
+    }
+    if (preg_match("/size limit/i", $error) || preg_match("/size limit/i", $error2)){
+      $_SESSION['limit_exceeded']= TRUE;
+    }
+
+   foreach ($res as $value){
+      if (isset($value["description"][0])){
+        $this->grouplist[$value["dn"]]= $value["cn"][0]." [".
+          $value["description"][0]."]";
+      } else {
+        $this->grouplist[$value["dn"]]= $value["cn"][0];
+      }
+    }
+
+    natcasesort ($this->grouplist);
+    reset ($this->grouplist);
+  }
+
+
+
+
+
+
+
+
+
+
+
+
+  function reload()
+  {
+    /* Get config */
+    $groupfilter= get_global('groupfilter');
+
+    /* Set base for all searches */
+    $base= $groupfilter['depselect'];
+
+    /* Regex filter? */
+    if ($groupfilter['regex'] != ""){
+      $regex= $groupfilter['regex'];
+    } else {
+      $regex= "*";
+    }
+
+    /* User filter? */
+    $filter= "";
+    $error= "";
+    $error2= "";
+    $this->grouplist= array();
+
+    /* What are primary groups? */
+    $primaries= array();
+    $ldap= $this->config->get_ldap_link(TRUE);
+    $ldap->cd($base);
+    $ldap->ls("(&(uid=$regex)(!(uid=*$))(objectClass=posixAccount)(gidNumber=*))", array("gidNumber", "cn"));
+    $error= $ldap->error;
+    while ($attrs= $ldap->fetch()){
+      $primaries[$attrs['gidNumber'][0]]= $attrs['cn'][0];
+    }
+
+    if ($groupfilter['primarygroups'] == "checked"){
+      $filter.= "(&(objectClass=posixGroup)(|";
+      foreach ($primaries as $gidNumber => $cn){
+        $filter.= "(gidNumber=$gidNumber)";
+      }
+      $filter.= "))";
+    } else {
+      $filter.= "(&(objectClass=posixGroup)(!(|";
+      foreach ($primaries as $gidNumber => $cn){
+        $filter.= "(gidNumber=$gidNumber)";
+      }
+      $filter.= ")))";
+    }
 
   
     /* Set filter depending on selection */
@@ -523,7 +649,7 @@ class groupManagement extends plugin
     if ($groupfilter['functionalgroups'] == "checked"){
       $ldap->cd($base);
       $ldap->set_size_limit($_SESSION['size_limit']);
-      $ldap->search("(&(cn=$regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))", array("cn", "gidNumber", "description"));
+      $ldap->ls("(&(cn=$regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))", array("cn", "gidNumber", "description"));
       $error2= $ldap->error;
       while ($attrs= $ldap->fetch()){
         if (!isset($primaries[$attrs['gidNumber'][0]])){
@@ -539,7 +665,7 @@ class groupManagement extends plugin
     $base2 = preg_replace("/ou=people,/i","",$base);
 
     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
-                              TRUE, $base2, array("ou", "description"), TRUE);
+                              FALSE, $base2, array("ou", "description"), TRUE);
 
     $this->departments= array();
     $tmp = array();
@@ -563,9 +689,9 @@ class groupManagement extends plugin
       }
     }
     if ($groupfilter['subsearch'] == "checked"){
-      $res= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("cn", "description", "gidNumber"), TRUE);
+      $res= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("cn", "description", "gidNumber"), TRUE);
     } else {
-      $base= get_groups_ou().$base;
+     $base= get_groups_ou().$base;
       $res= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("cn", "description", "gidNumber"), TRUE);
     }
     if (preg_match("/size limit/i", $error) || preg_match("/size limit/i", $error2)){