Code

Moved folder icon
[gosa.git] / gosa-core / plugins / admin / ogroups / class_ogroup.inc
index e1de54451c27a93b4db5490a72aa5b85ac128003..ea6abd6375bf24de950235b5c5a17fad3af293b7 100644 (file)
@@ -1,5 +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
+ */
 
 /* Sort multidimensional arrays for key 'text' */
 function sort_list($val1, $val2)
@@ -55,14 +74,14 @@ class ogroup extends plugin
     $this->is_account= TRUE;
 
     /* Get global filter config */
-    if (!is_global("ogfilter")){
+    if (!session::is_set("ogfilter")){
       $ui= get_userinfo();
       $base= get_base_from_people($ui->dn);
       $ogfilter= array( "dselect"       => $base,
           "regex"           => "*");
-      register_global("ogfilter", $ogfilter);
+      session::set("ogfilter", $ogfilter);
     }
-    $ogfilter= get_global('ogfilter');
+    $ogfilter= session::get('ogfilter');
 
     /* Adjust flags */
     foreach( array(   "U" => "accounts",
@@ -71,6 +90,7 @@ class ogroup extends plugin
           "D" => "departments",
           "S" => "servers",
           "W" => "workstations",
+          "O" => "winstations",
           "T" => "terminals",
           "F" => "phones",
           "_" => "subtrees",
@@ -82,17 +102,17 @@ class ogroup extends plugin
         $ogfilter[$val]= "";
       }
     }
-    register_global("ogfilter", $ogfilter);
+    session::set("ogfilter", $ogfilter);
   
     if(session::is_set('CurrentMainBase')){
-     $this->base = $_SESSION['CurrentMainBase'];
+     $this->base  = session::get('CurrentMainBase');
     }
 
     /* Set base */
     if ($this->dn == "new"){
-      $this->base= $_SESSION['CurrentMainBase'];
+      $this->base = session::get('CurrentMainBase');
     } else {
-      $this->base= preg_replace("/^[^,]+,".get_groups_ou()."/","",$this->dn);
+      $this->base= preg_replace("/^[^,]+,".normalizePreg(get_ou("ogroupou"))."/","",$this->dn);
     }
 
     /* Load member data */
@@ -126,12 +146,27 @@ class ogroup extends plugin
 
       /* Add objects to group */
       if (isset($_POST['add_object_finish']) && isset($_POST['objects'])){
+
+        $tmp = "";
+        foreach($this->memberList as $obj){
+          $tmp .= $obj['type'];
+        }
+        $skipped = FALSE;
         foreach ($_POST['objects'] as $value){
-          $this->memberList["$value"]= $this->objects[$value];
-          $this->member["$value"]= $value;
-          unset ($this->objects[$value]);
-          uasort ($this->memberList, 'sort_list');
-          reset ($this->memberList);
+          if(preg_match("/T/",$tmp) && $this->objects[$value]['type'] == "W"){
+            $skipped =TRUE;
+          }elseif(preg_match("/W/",$tmp) && $this->objects[$value]['type'] == "T"){
+            $skipped =TRUE;
+          }else{
+            $this->memberList["$value"]= $this->objects[$value];
+            $this->member["$value"]= $value;
+            unset ($this->objects[$value]);
+            uasort ($this->memberList, 'sort_list');
+            reset ($this->memberList);
+          }
+        }
+        if($skipped){
+          msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
         }
         $this->reload();
       }
@@ -152,37 +187,10 @@ class ogroup extends plugin
     /* Do we represent a valid group? */
     if (!$this->is_account){
       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
-        _("This 'dn' is no object group.")."</b>";
+        msgPool::noValidExtension("object group")."</b>";
       return ($display);
     }
 
-    /* Delete objects from group */
-    if (isset($_POST['delete_membership']) && isset($_POST['members'])){
-      foreach ($_POST['members'] as $value){
-        if(isset($this->memberList[$value])){
-          $this->objects["$value"]= $this->memberList[$value];
-          unset ($this->memberList["$value"]);
-          unset ($this->member["$value"]);
-          uasort ($this->objects, 'sort_list');
-          reset ($this->objects);
-        }
-      }
-      $this->reload();
-    }
-
-    /* Add objects to group */
-    if (isset($_POST['add_object_finish']) && isset($_POST['objects'])){
-      foreach ($_POST['objects'] as $value){
-        if(isset($this->objects[$value])){
-          $this->memberList["$value"]= $this->objects[$value];
-          $this->member["$value"]= $value;
-          unset ($this->objects[$value]);
-          uasort ($this->memberList, 'sort_list');
-          reset ($this->memberList);
-        }
-      }
-      $this->reload();
-    }
 
     /* Load templating engine */
     $smarty= get_smarty();
@@ -238,7 +246,7 @@ class ogroup extends plugin
     if ($this->group_dialog){
 
       /* Save data */
-      $ogfilter= get_global("ogfilter");
+      $ogfilter= session::get("ogfilter");
       foreach( array("dselect", "regex") as $type){
         if (isset($_POST[$type])){
           $ogfilter[$type]= $_POST[$type];
@@ -246,7 +254,7 @@ class ogroup extends plugin
       }
       if (isset($_POST['dselect'])){
         foreach( array("accounts", "groups", "applications", "departments",
-              "servers", "workstations", "terminals", "printers","subtrees",
+              "servers", "workstations", "winstations", "terminals", "printers","subtrees",
               "phones") as $type){
 
           if (isset($_POST[$type])) {
@@ -263,7 +271,7 @@ class ogroup extends plugin
         }
         $ogfilter['regex']= $s;
       }
-      register_global("ogfilter", $ogfilter);
+      session::set("ogfilter", $ogfilter);
       $this->reload();
 
       /* Calculate actual groups */
@@ -271,18 +279,56 @@ class ogroup extends plugin
 
       /* Show dialog */
       $smarty->assign("search_image", get_template_path('images/search.png'));
-      $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
+      $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
       $smarty->assign("tree_image", get_template_path('images/tree.png'));
       $smarty->assign("deplist", $this->config->idepartments);
       $smarty->assign("alphabet", generate_alphabet());
-      foreach( array("dselect", "regex", "accounts", "groups", "applications",
-            "departments", "servers", "workstations", "terminals","subtrees",
-            "printers", "phones") as $type){
+      foreach( array("dselect", "regex", "subtrees") as $type){
         $smarty->assign("$type", $ogfilter[$type]);
       }
       $smarty->assign("hint", print_sizelimit_warning());
       $smarty->assign("apply", apply_filter());
 
+      /* Build up checkboxes 
+       */
+      $ar = array(
+          "departments" => array(
+            "T" => msgPool::selectToView(_("departments")),
+            "C" => (isset($ogfilter['departments']) && ($ogfilter['departments'])),
+            "L" => sprintf(_("Show %s"),_("departments"))),
+          "accounts" => array(
+            "T" => msgPool::selectToView(_("people")),
+            "C" => (isset($ogfilter['accounts']) && ($ogfilter['accounts'])),
+            "L" => sprintf(_("Show %s"),_("people"))),
+          "groups"=> array(
+            "T" => msgPool::selectToView(_("groups")),
+            "C" => (isset($ogfilter['groups']) && ($ogfilter['groups'])),
+            "L" => sprintf(_("Show %s"),_("groups"))),
+          "applications"=> array(
+            "T" => msgPool::selectToView(_("applications")),
+            "C" => (isset($ogfilter['applications']) && ($ogfilter['applications'])),
+            "L" => sprintf(_("Show %s"),_("applications"))),
+          "servers"=> array(
+            "T" => msgPool::selectToView(_("servers")),
+            "C" => (isset($ogfilter['servers']) && ($ogfilter['servers'])),
+            "L" => sprintf(_("Show %s"),_("servers"))),
+          "workstations"=> array(
+            "T" => msgPool::selectToView(_("workstations")),
+            "C" => (isset($ogfilter['workstations']) && ($ogfilter['workstations'])),
+            "L" => sprintf(_("Show %s"),_("workstations"))),
+          "terminals"=> array(
+            "T" => msgPool::selectToView(_("terminals")),
+            "C" => (isset($ogfilter['terminals']) && ($ogfilter['terminals'])),
+            "L" => sprintf(_("Show %s"),_("terminals"))),
+          "printers"=> array(
+            "T" => msgPool::selectToView(_("printer")),
+            "C" => (isset($ogfilter['printers']) && ($ogfilter['printers'])),
+            "L" => sprintf(_("Show %s"),_("printers"))),
+          "phones"=> array(
+            "T" => msgPool::selectToView(_("phones")),
+            "C" => (isset($ogfilter['phones']) && ($ogfilter['phones'])),
+            "L" => sprintf(_("Show %s"),_("phones"))));
+      $smarty->assign("checkboxes",$ar);
       $display= $smarty->fetch (get_template_path('ogroup_objects.tpl', TRUE, dirname(__FILE__)));
       return ($display);
     }
@@ -304,6 +350,7 @@ class ogroup extends plugin
           "D" => _("departments"),
           "S" => _("servers"),
           "W" => _("workstations"),
+          "O" => _("winstations"),
           "T" => _("terminals"),
           "F" => _("phones"),
           "P" => _("printers"));
@@ -311,9 +358,9 @@ class ogroup extends plugin
       $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
       $p1= $conv[$type[0]];
       error_reporting(0);
-      if (isset($type[1]) && preg_match('/[UGADSFWTP]/', $type[1])){
+      if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
         $p2= $conv[$type[1]];
-        $smarty->assign("combinedObjects", "$p1 "._("and")." $p2");
+        $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
       } else {
         $smarty->assign("combinedObjects", "$p1");
       }
@@ -374,7 +421,7 @@ class ogroup extends plugin
     $filter                       = "";
     $objectClasses                = array();
     
-    $ogfilter               = get_global("ogfilter");
+    $ogfilter               = session::get("ogfilter");
     $regex                  = $ogfilter['regex'];
 
     $ldap= $this->config->get_ldap_link();
@@ -386,11 +433,12 @@ class ogroup extends plugin
       ###########*/
 
     $p_f= array("accounts"        => array("CLASS"=>"gosaAccount"    ,"DN"=> get_people_ou()           ,"ACL" => "users"), 
-                "groups"          => array("CLASS"=>"posixGroup"     ,"DN"=> get_groups_ou()           ,"ACL" => "groups"), 
+                "groups"          => array("CLASS"=>"posixGroup"     ,"DN"=> get_groups_ou('ogroupou') ,"ACL" => "groups"), 
                 "applications"    => array("CLASS"=>"gosaApplication","DN"=> get_ou('applicationou')   ,"ACL" => "application"), 
                 "departments"     => array("CLASS"=>"gosaDepartment" ,"DN"=> ""                        ,"ACL" => "department"), 
                 "servers"         => array("CLASS"=>"goServer"       ,"DN"=> get_ou('serverou')        ,"ACL" => "server"),
                 "workstations"    => array("CLASS"=>"gotoWorkstation","DN"=> get_ou('workstationou')   ,"ACL" => "workstation"),
+                "winstations"    => array("CLASS"=>"opsiClient",        "DN"=> get_ou('WINSTATIONS')     ,"ACL" => "winstation"),
                 "terminals"       => array("CLASS"=>"gotoTerminal"   ,"DN"=> get_ou('terminalou')      ,"ACL" => "terminal"),
                 "printers"        => array("CLASS"=>"gotoPrinter"    ,"DN"=> get_ou('printerou')       ,"ACL" => "printer"),
                 "phones"          => array("CLASS"=>"goFonHardware"  ,"DN"=> get_ou('phoneou')         ,"ACL" => "phone"));
@@ -453,10 +501,10 @@ class ogroup extends plugin
          it seams that this entry was removed 
        */ 
       /* Try to resolv the entry again, if it still fails, display error msg */
-      $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass"));
+      $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
 
       /* It has failed, add entry with type flag I (Invalid)*/
-      if ($ldap->error != "Success"){
+      if (!$ldap->success()){
         $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".@LDAP::fix($dn),"type" => "I");
 
       } else {
@@ -477,6 +525,13 @@ class ogroup extends plugin
           $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
         }
         $this->objcache[$attrs["dn"]]['objectClass']  = $attrs['objectClass'];
+
+        if(isset($attrs['macAddress'][0])){
+          $this->objcache[$attrs["dn"]]['macAddress']  = $attrs['macAddress'][0];
+        }else{
+          $this->objcache[$attrs["dn"]]['macAddress']  = "";
+        }
+
         if(isset($attrs['uid'])){
           $this->objcache[$attrs["dn"]]['uid']          = $attrs['uid'];
         }
@@ -521,6 +576,7 @@ class ogroup extends plugin
         "D" => "select_department.png",
         "S" => "select_server.png",
         "W" => "select_workstation.png",
+        "O" => "select_winstation.png",
         "T" => "select_terminal.png",
         "F" => "select_phone.png",
         "I" => "flag.png",
@@ -545,6 +601,7 @@ class ogroup extends plugin
           "D" => "gosaDepartment",
           "S" => "goServer",
           "W" => "gotoWorkstation",
+          "O" => "opsiClient",
           "T" => "gotoTerminal",
           "F" => "goFonHardware",
           "P" => "gotoPrinter") as $index => $class){
@@ -587,7 +644,7 @@ class ogroup extends plugin
 
     /* Permissions for that base? */
     if ($this->base != ""){
-      $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
+      $new_dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
     } else {
       $new_dn= $this->dn;
     }
@@ -599,7 +656,7 @@ class ogroup extends plugin
     }
     
     if($ldap->count() !=0){
-      $message[]= _("There is already an object with this cn.");
+      $message[]= msgPool::duplicated(_("Name"));
     } 
 
     /* Set new acl base */
@@ -609,12 +666,12 @@ class ogroup extends plugin
 
     /* must: cn */
     if ($this->cn == ""){
-      $message[]= "The required field 'Name' is not set.";
+      $message[]= msgPool::required(_("Name"));
     }
 
     /* To many different object types? */
     if (strlen($this->gosaGroupObjects) > 4){
-      $message[]= _("You can combine two different object types at maximum only!");
+      $message[]= _("You can combine two different object types at maximum, only!");
     }
 
     return ($message);
@@ -636,7 +693,7 @@ class ogroup extends plugin
 
     /* New accounts need proper 'dn', propagate it to remaining objects */
     if ($this->dn == 'new'){
-      $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
+      $this->dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
     }
 
     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
@@ -670,7 +727,8 @@ class ogroup extends plugin
     $this->handle_post_events($mode);
 
     $ret= 0;
-    if (show_ldap_error($ldap->get_error(), sprintf(_("Saving of object group/generic with dn '%s' failed."),$this->dn))){
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
       $ret= 1;
     }
 
@@ -683,7 +741,9 @@ class ogroup extends plugin
 
     $ldap= $this->config->get_ldap_link();
     $ldap->rmdir($this->dn);
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of object group/generic with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+    }
 
     new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());