Code

Added branches container for old stuff
[gosa.git] / gosa-core / plugins / personal / posix / class_posixAccount.inc
index bbcebfdcd94a7e38c8da64d05280199cbab694e9..139f6973243639c74cbd635eb52d7024147f6492 100644 (file)
@@ -1,4 +1,25 @@
 <?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
+ */
+
 /*!
   \brief   posixAccount plugin
   \author  Cajus Pollmeier <pollmeier@gonicus.de>
@@ -14,12 +35,7 @@ class posixAccount extends plugin
 {
   /* Definitions */
   var $plHeadline= "UNIX";
-  var $plDescription= "This does something";
-
-  /* CLI vars */
-  var $cli_summary= "Manage users posix account";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+  var $plDescription= "Edit users POSIX settings";
 
   /* Plugin specific values */
   var $homeDirectory= "";
@@ -140,9 +156,9 @@ class posixAccount extends plugin
           $this->status.= ", "._("grace time active");
         }
       } elseif (($this->shadowLastChange + $this->shadowMin) >= $current){
-        $this->status= _("active, password not changable");
+        $this->status= _("active").", "._("password not changeable");
       } elseif (($this->shadowLastChange + $this->shadowMax) >= $current){
-        $this->status= _("activepassword expired");
+        $this->status= _("active").", "._("password expired");
       } else {
         $this->status= _("active");
       }
@@ -151,12 +167,11 @@ class posixAccount extends plugin
       $ldap->cd($this->config->current['BASE']);
       $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("cn", "description"));
 
-      while ($this->attrs= $ldap->fetch()){
-        if (!isset($this->attrs["description"][0])){
-          $entry= $this->attrs["cn"][0];
+      while ($attrs= $ldap->fetch()){
+        if (!isset($attrs["description"][0])){
+          $entry= $attrs["cn"][0];
         } else {
-          $dsc= preg_replace ('/^Group of user/', _("Group of user"), $this->attrs["description"][0]);
-          $entry= $this->attrs["cn"][0]." [$dsc]";
+          $entry= $attrs["cn"][0]." [".$attrs["description"][0]."]";
         }
         $this->groupMembership[$ldap->getDN()]= $entry;
       }
@@ -210,12 +225,12 @@ class posixAccount extends plugin
     asort ($this->secondaryGroups);
 
     /* Get global filter config */
-    if (!is_global("sysfilter")){
+    if (!session::is_set("sysfilter")){
       $ui= get_userinfo();
       $base= get_base_from_people($ui->dn);
       $sysfilter= array( "depselect"       => $base,
           "regex"           => "*");
-      register_global("sysfilter", $sysfilter);
+      session::set("sysfilter", $sysfilter);
     }
     $this->ui = get_userinfo();
   }
@@ -236,7 +251,7 @@ class posixAccount extends plugin
 
     /* Department has changed? */
     if(isset($_POST['depselect'])){
-      $_SESSION['CurrentMainBase']= validate($_POST['depselect']);
+      session::set('CurrentMainBase',validate($_POST['depselect']));
     }
 
     if($this->multiple_support_active){
@@ -256,8 +271,8 @@ class posixAccount extends plugin
 
       /* Do we represent a valid posixAccount? */
       if (!$this->is_account && $this->parent === NULL ){
-        $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
-          _("This account has no unix extensions.")."</b>";
+        $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
+          msgPool::noValidExtension(_("POSIX"))."</b>";
         $display.= back_to_main();
         return ($display);
       }
@@ -277,15 +292,12 @@ class posixAccount extends plugin
                in the moment, because I need to rely on unique
                uidNumbers. There'll be a better solution later
                on. */
-            $display= $this->show_disable_header(_("Remove posix account"),
-                _("This account has unix features enabled. To disable them, you'll need to remove the samba / environment account first."), TRUE);
+            $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("POSIX")), msgPool::featuresEnabled(_("POSIX"), array(_("Samba"), _("Environment"))), TRUE);
           } else {
-            $display= $this->show_disable_header(_("Remove posix account"),
-                _("This account has posix features enabled. You can disable them by clicking below."));
+            $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("POSIX")), msgPool::featuresEnabled(_("POSIX")));
           }
         } else {
-          $display= $this->show_enable_header(_("Create posix account"),
-              _("This account has posix features disabled. You can enable them by clicking below."));
+          $display= $this->show_enable_header(msgPool::addFeaturesButton(_("POSIX")), msgPool::featuresDisabled(_("POSIX")));
           return($display);
         }
       }
@@ -352,7 +364,7 @@ class posixAccount extends plugin
     /* Show ws dialog */
     if ($this->show_ws_dialog){
       /* Save data */
-      $sysfilter= get_global("sysfilter");
+      $sysfilter= session::get("sysfilter");
       foreach( array("depselect", "regex") as $type){
         if (isset($_POST[$type])){
           $sysfilter[$type]= $_POST[$type];
@@ -365,7 +377,7 @@ class posixAccount extends plugin
         }
         $sysfilter['regex']= $s;
       }
-      register_global("sysfilter", $sysfilter);
+      session::set("sysfilter", $sysfilter);
 
       /* Get workstation list */
       $exclude= "";
@@ -376,16 +388,27 @@ class posixAccount extends plugin
         $exclude= "(!(|$exclude))";
       }
       $regex= $sysfilter['regex'];
+
+      $acls = array();
+      if(class_available("servgeneric")) $acls[] = "server";
+      if(class_available("workgeneric")) $acls[] = "worstation";
+      if(class_available("termgeneric")) $acls[] = "terminal";
+
       $filter= "(&(|(objectClass=goServer)(objectClass=gotoWorkstation)(objectClass=gotoTerminal))$exclude(cn=*)(cn=$regex))";
-      $res= get_list($filter, "groups", $sysfilter['depselect'], array("cn"), GL_SUBSEARCH | GL_SIZELIMIT);
+
+      $deps_a = array(get_ou("serverou"),
+                      get_ou("terminalou"),
+                      get_ou("workstationou")); 
+
+      $res= get_sub_list($filter, $acls, $deps_a, get_ou("systemsou").$sysfilter['depselect'], array("cn"), GL_SUBSEARCH | GL_SIZELIMIT);
       $wslist= array();
       foreach ($res as $attrs){
         $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
       }
       asort($wslist);
-      $smarty->assign("search_image", get_template_path('images/search.png'));
-      $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
-      $smarty->assign("tree_image", get_template_path('images/tree.png'));
+      $smarty->assign("search_image", get_template_path('images/lists/search.png'));
+      $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
+      $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
       $smarty->assign("deplist", $this->config->idepartments);
       $smarty->assign("alphabet", generate_alphabet());
       foreach( array("depselect", "regex") as $type){
@@ -421,12 +444,12 @@ class posixAccount extends plugin
       $smarty->assign("regex",$this->GroupRegex);
       $smarty->assign("guser",$this->GroupUserRegex);
       $smarty->assign("groups", $glist);
-      $smarty->assign("search_image", get_template_path('images/search.png'));
-      $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
-      $smarty->assign("tree_image", get_template_path('images/tree.png'));
+      $smarty->assign("search_image", get_template_path('images/lists/search.png'));
+      $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
+      $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
       $smarty->assign("deplist", $this->config->idepartments);
       $smarty->assign("alphabet", generate_alphabet());
-      $smarty->assign("depselect",$_SESSION['CurrentMainBase']);
+      $smarty->assign("depselect", session::get('CurrentMainBase'));
       $smarty->assign("hint", print_sizelimit_warning());
 
       $smarty->assign("apply", apply_filter());
@@ -438,7 +461,7 @@ class posixAccount extends plugin
     $smarty= get_smarty();
 
     /* In 'MyAccount' mode, we must remove write acls if we are not in editing mode. */ 
-    $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
+    $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
 
     /* Depending on pwmode, currently hardcoded because there are no other methods */
     if ( 1 == 1 ){
@@ -453,11 +476,11 @@ class posixAccount extends plugin
                                               "<input name=\"shadowMax\" size=3 maxlength=4 value=\"".$this->shadowMax."\">"));
 
       $shadowInactiveACL=  $this->getacl("shadowInactive",$SkipWrite);
-      $smarty->assign("shadowinactives", sprintf(_("Disable account after %s days of inactivity after password expiery"), 
+      $smarty->assign("shadowinactives", sprintf(_("Disable account after %s days of inactivity after password expiry"), 
                                               "<input name=\"shadowInactive\" size=3 maxlength=4 value=\"".$this->shadowInactive."\">"));
 
       $shadowWarningACL =  $this->getacl("shadowWarning",$SkipWrite);
-      $smarty->assign("shadowwarnings", sprintf(_("Warn user %s days before password expiery"), 
+      $smarty->assign("shadowwarnings", sprintf(_("Warn user %s days before password expiry"), 
                                               "<input name=\"shadowWarning\" size=3 maxlength=4 value=\"".$this->shadowWarning."\">"));
 
       foreach( array("activate_shadowMin", "activate_shadowMax",
@@ -491,9 +514,7 @@ class posixAccount extends plugin
     for($y= $date['year']-10; $y<$date['year']+10; $y++){
       $years[]= $y;
     }
-    $months= array(_("January"), _("February"), _("March"), _("April"),
-        _("May"), _("June"), _("July"), _("August"), _("September"),
-        _("October"), _("November"), _("December"));
+    $months= msgPool::months();
     $smarty->assign("day", $date["mday"]);
     $smarty->assign("days", $days);
     $smarty->assign("months", $months);
@@ -527,17 +548,26 @@ class posixAccount extends plugin
     /* Checkboxes */
     if ($this->force_ids == 1){
       $smarty->assign("force_ids", "checked");
-      if ($_SESSION['js']){
+      if (session::get('js')){
         $smarty->assign("forceMode", "");
       }
     } else {
-      if ($_SESSION['js']){
+      if (session::get('js')){
         $smarty->assign("forceMode", "disabled");
       }
       $smarty->assign("force_ids", "");
     }
-    
 
+    /* Create onClick="" action string for the "Force UID/GID" option 
+     */
+    $onClickIDS ="";
+    if(preg_match("/w/",$this->getacl("uidNumber",$SkipWrite))){
+      $onClickIDS .= "changeState('uidNumber');";
+    }
+    if(preg_match("/w/",$this->getacl("gidNumber",$SkipWrite))){
+      $onClickIDS .= "changeState('gidNumber');";
+    }
+    $smarty->assign("onClickIDS", $onClickIDS);
     $smarty->assign("force_idsACL", $this->getacl("uidNumber",$SkipWrite).$this->getacl("gidNumber",$SkipWrite));
 
     foreach(array("primaryGroup","trustmode","activate_shadowWarning","activate_shadowInactive","activate_shadowMin","activate_shadowMax","activate_shadowExpire","mustchangepassword") as $val){
@@ -557,7 +587,7 @@ class posixAccount extends plugin
         $smarty->assign("use_".$val,FALSE);
       }
 
-      if(($_SESSION["js"])&&(($val=="uidNumber")||($val=="gidNumber")))
+      if((session::get("js"))&&(($val=="uidNumber")||($val=="gidNumber")))
       {
         $smarty->assign("$val"."ACL",$this->getacl($val,$SkipWrite));
         $smarty->assign("$val", $this->$val);
@@ -623,8 +653,6 @@ class posixAccount extends plugin
       return;
     }
 
-    /* include global link_info */
-    $ldap= $this->config->get_ldap_link();
 
     /* Remove and write to LDAP */
     plugin::remove_from_parent();
@@ -637,14 +665,18 @@ class posixAccount extends plugin
     unset($this->attrs['trustModel']);
 
     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
-        $this->attributes, "Save");
+    /* include global link_info */
+     $this->attributes, "Save");
+    $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->dn);
     $this->cleanup();
     $ldap->modify ($this->attrs); 
 
     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/posix account with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
+    }
 
     /* Delete group only if cn is uid and there are no other
        members inside */
@@ -761,9 +793,6 @@ class posixAccount extends plugin
   function save()
   {
 
-    /* include global link_info */
-    $ldap= $this->config->get_ldap_link();
-
     /* Adapt shadow values */
     if (!$this->activate_shadowExpire){
       $this->shadowExpire= "0";
@@ -800,7 +829,7 @@ class posixAccount extends plugin
 
           /* Oups - timed out */
           if ($wait-- == 0){
-            print_red (_("Failed: overriding lock"));
+            msg_dialog::display(_("Warning"), _("Timeout while waiting for lock. Ignoring lock!"), WARNING_DIALOG);
             break;
           }
         }
@@ -883,9 +912,22 @@ class posixAccount extends plugin
     }
 
 
-    /* Save data to LDAP */
-    $ldap->cd($this->dn);
+    /* include global link_info */
     $this->cleanup();
+    /* This is just a test, we have had duplicated ids 
+        in the past when copy & paste was used. 
+       Normaly this should not happen.
+     */ 
+    if(isset($this->attrs['uidNumber']) && !$this->force_ids){
+      $used = $this->get_used_uid_numbers();
+      if(isset($used[$this->attrs['uidNumber']]) && $used[$this->attrs['uidNumber']] != $this->dn){
+        msg_dialog::display(_("Warning"),_("A duplicated UID number was written for this user. If this was not intended please verify all used uidNumbers!"), WARNING_DIALOG);
+      }
+    }
+
+    $ldap= $this->config->get_ldap_link();
+    $ldap->cd($this->dn);
     unset($this->attrs['uid']);
     $ldap->modify ($this->attrs); 
 
@@ -896,7 +938,9 @@ class posixAccount extends plugin
       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/posix account with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+    }
 
     /* Remove lock needed for unique id generation */
     del_lock ("uidnumber");
@@ -909,13 +953,13 @@ class posixAccount extends plugin
 
       /* Create group if it doesn't exist */
       if ($ldap->count() == 0){
-        $groupdn= preg_replace ('/^'.$this->config->current['DNMODE'].'=[^,]+,'.get_people_ou().'/i', 'cn='.$this->uid.','.get_groups_ou(), $this->dn);
+        $groupdn= preg_replace ('/^'.$this->config->get_cfg_value("dnmode").'=[^,]+,'.get_people_ou().'/i', 'cn='.$this->uid.','.get_groups_ou(), $this->dn);
 
         $g= new group($this->config, $groupdn);
         $g->cn= $this->uid;
         $g->force_gid= 1;
         $g->gidNumber= $this->gidNumber;
-        $g->description= "Group of user ".$this->givenName." ".$this->sn;
+        $g->description= _("Group of user")." ".$this->givenName." ".$this->sn;
         $g->save ();
       }
     }
@@ -971,78 +1015,128 @@ class posixAccount extends plugin
 
     /* must: homeDirectory */
     if ($this->homeDirectory == ""){
-      $message[]= _("The required field 'Home directory' is not set.");
+      $message[]= msgPool::required(_("Home directory"));
     }
-    if (!is_path($this->homeDirectory)){
-      $message[]= _("Please enter a valid path in 'Home directory' field.");
+    if (!tests::is_path($this->homeDirectory)){
+      $message[]= msgPool::invalid(_("Home directory"), "", "", "/home/yourname" );
     }
 
     /* Check ID's if they are forced by user */
     if ($this->force_ids == "1"){
 
       /* Valid uid/gid? */
-      if (!is_id($this->uidNumber)){
-        $message[]= _("Value specified as 'UID' is not valid.");
+      if (!tests::is_id($this->uidNumber)){
+        $message[]= msgPool::invalid(_("UID"), $this->uidNumber, "/[0-9]/");
       } else {
-        if ($this->uidNumber < $this->config->current['MINID']){
-          $message[]= _("Value specified as 'UID' is too small.");
+        if ($this->uidNumber < $this->config->get_cfg_value("minid")){
+          $message[]= msgPool::toosmall(_("UID"), $this->config->get_cfg_value("minid"));
         }
       }
-      if (!is_id($this->gidNumber)){
-        $message[]= _("Value specified as 'GID' is not valid.");
+      if (!tests::is_id($this->gidNumber)){
+        $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/");
       } else {
-        if ($this->gidNumber < $this->config->current['MINID']){
-          $message[]= _("Value specified as 'GID' is too small.");
+        if ($this->gidNumber < $this->config->get_cfg_value("minid")){
+          $message[]= msgPool::toosmall(_("GID"), $this->config->get_cfg_value("minid"));
         }
       }
     }
 
     /* Check shadow settings, well I like spaghetties... */
     if ($this->activate_shadowMin){
-      if (!is_id($this->shadowMin)){
-        $message[]= _("Value specified as 'shadowMin' is not valid.");
+      if (!tests::is_id($this->shadowMin)){
+        $message[]= msgPool::invalid(_("shadowMin"), $this->shadowMin, "/[0-9]/");
       }
     }
     if ($this->activate_shadowMax){
-      if (!is_id($this->shadowMax)){
-        $message[]= _("Value specified as 'shadowMax' is not valid.");
+      if (!tests::is_id($this->shadowMax)){
+        $message[]= msgPool::invalid(_("shadowMax"), $this->shadowMax, "/[0-9]/");
       }
     }
     if ($this->activate_shadowWarning){
-      if (!is_id($this->shadowWarning)){
-        $message[]= _("Value specified as 'shadowWarning' is not valid.");
+      if (!tests::is_id($this->shadowWarning)){
+        $message[]= msgPool::invalid(_("shadowWarning"), $this->shadowWarning, "/[0-9]/");
       }
       if (!$this->activate_shadowMax){
-        $message[]= _("'shadowWarning' without 'shadowMax' makes no sense.");
+        $message[]= msgPool::depends("shadowWarning", "shadowMax");
       }
       if ($this->shadowWarning > $this->shadowMax){
-        $message[]= _("Value specified as 'shadowWarning' should be smaller than 'shadowMax'.");
+        $message[]= msgPool::toobig("shadowWarning", "shadowMax");
       }
       if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin){
-        $message[]= _("Value specified as 'shadowWarning' should be greater than 'shadowMin'.");
+        $message[]= msgPool::toosmall("shadowWarning", "shadowMin");
       }
     }
     if ($this->activate_shadowInactive){
-      if (!is_id($this->shadowInactive)){
-        $message[]= _("Value specified as 'shadowInactive' is not valid.");
+      if (!tests::is_id($this->shadowInactive)){
+        $message[]= msgPool::invalid(_("shadowInactive"), $this->shadowInactive, "/[0-9]/");
       }
       if (!$this->activate_shadowMax){
-        $message[]= _("'shadowInactive' without 'shadowMax' makes no sense.");
+        $message[]= msgPool::depends("shadowInactive", "shadowMax");
       }
     }
     if ($this->activate_shadowMin && $this->activate_shadowMax){
       if ($this->shadowMin > $this->shadowMax){
-        $message[]= _("Value specified as 'shadowMin' should be smaller than 'shadowMax'.");
+        $message[]= msgPool::toobig("shadowMin", "shadowMax");
       }
     }
 
-    //  if(empty($this->gosaDefaultPrinter)){
-    //    $message[]= _("You need to specify a valid default printer.");
-    //  }
-
     return ($message);
   }
 
+
+  function multiple_check()
+  {
+    $message = plugin::multiple_check();
+    if ($this->homeDirectory == "" && in_array("homeDirectory",$this->multi_boxes)){
+      $message[]= msgPool::required(_("Home directory"));
+    }
+    if (!tests::is_path($this->homeDirectory) && in_array("homeDirectory",$this->multi_boxes)){
+      $message[]= msgPool::invalid(_("Home directory"), "", "", "/home/yourname" );
+    }
+
+    /* Check shadow settings, well I like spaghetties... */
+    if ($this->activate_shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){
+      if (!tests::is_id($this->shadowMin)){
+        $message[]= msgPool::invalid(_("shadowMin"), $this->shadowMin, "/[0-9]/");
+      }
+    }
+    if ($this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+      if (!tests::is_id($this->shadowMax)){
+        $message[]= msgPool::invalid(_("shadowMax"), $this->shadowMax, "/[0-9]/");
+      }
+    }
+    if ($this->activate_shadowWarning && in_array("activate_shadowWarning",$this->multi_boxes)){
+      if (!tests::is_id($this->shadowWarning)){
+        $message[]= msgPool::invalid(_("shadowWarning"), $this->shadowWarning, "/[0-9]/");
+      }
+      if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+        $message[]= msgPool::depends("shadowWarning", "shadowMax");
+      }
+      if ($this->shadowWarning > $this->shadowMax && in_array("activate_shadowWarning",$this->multi_boxes)){
+        $message[]= msgPool::toobig("shadowWarning", "shadowMax");
+      }
+      if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){
+        $message[]= msgPool::tosmall("shadowWarning", "shadowMin");
+      }
+    }
+    if ($this->activate_shadowInactive && in_array("activate_shadowInactive",$this->multi_boxes)){
+      if (!tests::is_id($this->shadowInactive)){
+        $message[]= msgPool::invalid(_("shadowInactive"), $this->shadowInactive, "/[0-9]/");
+      }
+      if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+        $message[]= msgPool::depends("shadowInactive", "shadowMax");
+      }
+    }
+    if ($this->activate_shadowMin && $this->activate_shadowMax && in_array("activate_shadowMin",$this->multi_boxes)){
+      if ($this->shadowMin > $this->shadowMax){
+        $message[]= msgPool::toobig("shadowMin", "shadowMax");
+      }
+    }
+
+    return($message);
+  }
+
+
   function addGroup ($groups)
   {
     /* include global link_info */
@@ -1096,12 +1190,12 @@ class posixAccount extends plugin
 
 
   /* Adapt from template, using 'dn' */
-  function adapt_from_template($dn)
+  function adapt_from_template($dn, $skip= array())
   {
     /* Include global link_info */
     $ldap= $this->config->get_ldap_link();
 
-    plugin::adapt_from_template($dn);
+    plugin::adapt_from_template($dn, $skip);
     $template= $this->attrs['uid'][0];
 
     /* Adapt group membership */
@@ -1169,6 +1263,22 @@ class posixAccount extends plugin
   }
 
 
+  function get_used_uid_numbers()
+  {
+    $ids= array();
+    $ldap= $this->config->get_ldap_link();
+
+    $ldap->cd ($this->config->current['BASE']);
+    $ldap->search ("(&(objectClass=posixAccount)(uidNumber=*))", array("uidNumber"));
+
+    /* Get list of ids */
+    while ($attrs= $ldap->fetch()){
+      $ids[$attrs['uidNumber'][0]] = $attrs['dn'];
+    }
+    return($ids);
+  }
+
+  
   function get_next_id($attrib, $dn)
   {
     $ids= array();
@@ -1192,10 +1302,10 @@ class posixAccount extends plugin
 
     /* get the ranges */
     $tmp = array('0'=> 1000); 
-    if (preg_match('/posixAccount/', $oc) && isset($this->config->current['UIDBASE'])) {
-      $tmp= split('-',$this->config->current['UIDBASE']);
-    } elseif(isset($this->config->current['GIDBASE'])){
-      $tmp= split('-',$this->config->current['GIDBASE']);
+    if (preg_match('/posixAccount/', $oc) && $this->config->get_cfg_value("uidbase") != ""){
+      $tmp= split('-',$this->config->get_cfg_value("uidbase"));
+    } elseif($this->config->get_cfg_value("gidbase") != ""){
+      $tmp= split('-',$this->config->get_cfg_value("gidbase"));
     }
 
     /* Set hwm to max if not set - for backward compatibility */
@@ -1207,7 +1317,7 @@ class posixAccount extends plugin
     }
 
     /* Find out next free id near to UID_BASE */
-    if (!isset($this->config->current['BASE_HOOK'])){
+    if ($this->config->get_cfg_value("base_hook") == ""){
       $base= $lwm;
     } else {
       /* Call base hook */
@@ -1221,7 +1331,7 @@ class posixAccount extends plugin
 
     /* Should not happen */
     if ($id == $hwm){
-      print_red(_("Too many users, can't allocate a free ID!"));
+      msg_dialog::display(_("Error"), _("Cannot allocate a free ID!"), ERROR_DIALOG);
       exit;
     }
 
@@ -1230,7 +1340,7 @@ class posixAccount extends plugin
   function reload()
   {
     /* Set base for all searches */
-    $base     = $_SESSION['CurrentMainBase'];
+    $base      = session::get('CurrentMainBase');
     $base     = $base;
     $ldap     = $this->config->get_ldap_link();    
     $attrs    =  array("cn", "description", "gidNumber");
@@ -1251,8 +1361,8 @@ class posixAccount extends plugin
     $res= get_list($filter, "groups", $base,$attrs, $Flags);
   
     /* check sizelimit */
-    if (preg_match("/size limit/i", $ldap->error)){
-      $_SESSION['limit_exceeded']= TRUE;
+    if (preg_match("/size limit/i", $ldap->get_error())){
+      session::set('limit_exceeded',TRUE);
     }
 
     /* Create a list of users */
@@ -1310,11 +1420,11 @@ class posixAccount extends plugin
     if(!$this->is_account) return("");
     if ($this->force_ids == 1){
       $force_ids = "checked";
-      if ($_SESSION['js']){
+      if (session::get('js')){
         $forceMode = "";
       }
     } else {
-      if ($_SESSION['js']){
+      if (session::get('js')){
         if($this->acl != "#none#")
           $forceMode ="disabled";
       }
@@ -1382,8 +1492,8 @@ class posixAccount extends plugin
     plugin::PrepareForCopyPaste($source);
 
     /* Avoid using the same gid/uid number as source user */
-    $this->savedUidNumber = $this->get_next_id("gidNumber", $this->dn);
-    $this->savedGidNumber = $this->get_next_id("uidNumber", $this->dn);
+    $this->savedUidNumber = $this->get_next_id("uidNumber", $this->dn);
+    $this->savedGidNumber = $this->get_next_id("gidNumber", $this->dn);
   }
 
 
@@ -1421,6 +1531,8 @@ class posixAccount extends plugin
             );
   }
 
+
+  /* Return selected values for multiple edit */
   function get_multi_edit_values()
   {
     $ret = plugin::get_multi_edit_values();
@@ -1444,36 +1556,50 @@ class posixAccount extends plugin
     if(in_array("mustchangepassword",$this->multi_boxes)){
       $ret['mustchangepassword'] = $this->mustchangepassword;
     }
-    print_a($this->multi_boxes);
-    print_a($ret);
     return($ret);
   }
 
 
+  /* Save posts for multiple edit 
+   */
   function multiple_save_object()
   {
     if(isset($_POST['posix_mulitple_edit'])){
+      /* Backup expire value */ 
+      $expire_tmp = $this->shadowExpire;
+  
+      /* Update all values */
       plugin::multiple_save_object();
+
+      /* Get selected checkboxes */
       foreach(array("primaryGroup","trustmode","mustchangepassword","activate_shadowWarning","activate_shadowInactive","activate_shadowMin", "activate_shadowMax","activate_shadowExpire") as $val){
         if(isset($_POST["use_".$val])){
           $this->multi_boxes[] = $val;
         }
       }
 
-      /* Get selected shadow checkboxes */
+      /* Update special values, checkboxes for posixShadow */
       foreach(array("shadowMin","shadowMax","shadowExpire","shadowInactive","shadowWarning") as $var) {
         if($this->acl_is_writeable($var)){
           $activate_var = "activate_".$var;
-          if(isset($_POST['activate_'.$var])){
-            $this->$activate_var  = true;
-            $this->$var      = $_POST[$var];
-          }else{
-            $this->$activate_var  = false;
-            $this->$var      = 0;
+          if(in_array($activate_var, $this->multi_boxes)){
+            if(isset($_POST['activate_'.$var])){
+              $this->$activate_var  = true;
+              $this->$var      = $_POST[$var];
+            }else{
+              $this->$activate_var  = false;
+              $this->$var      = 0;
+            }
           }
         }
       }
 
+      /* Restore shadow value, if the shadow attribute isn't used */
+      if(!in_array("activate_shadowExpire",$this->multi_boxes)){
+        $this->shadowExpire = $expire_tmp;
+      }
+
       /* Force change password ? */
       if(isset($_POST['mustchangepassword'])){
         $this->mustchangepassword = TRUE;
@@ -1498,7 +1624,6 @@ class posixAccount extends plugin
         }
       }
 
-
       /* Save primary group settings */
       if($this->acl_is_writeable("primaryGroup") && isset($_POST['primaryGroup'])){
         $data= $_POST['primaryGroup'];
@@ -1510,18 +1635,21 @@ class posixAccount extends plugin
     }
   }
 
+  
+  /* Initialize plugin with given atribute arrays 
+   */
   function init_multiple_support($attrs,$all)
   {
     plugin::init_multiple_support($attrs,$all);
 
-    restore_error_handler();
-
+    /* Some dummy values */
     $groups_some = array();
     $groups_all  = array();
     $groups_uid  = array();
-    $uids = array();
-    $first = TRUE;
+    $uids        = array();
+    $first       = TRUE;
 
+    /* Get all groups used by currently edited users */
     $uid_filter="";  
     for($i =0; $i < $this->multi_attrs_all['uid']['count'] ; $i ++){
       $uid = $this->multi_attrs_all['uid'][$i];
@@ -1539,6 +1667,7 @@ class posixAccount extends plugin
       }
     }
 
+    /* Create an array, containing all used groups */
     $groups_all = $groups_some;
     foreach($groups_all as $id => $group){
       foreach($uids as $uid){
@@ -1549,7 +1678,10 @@ class posixAccount extends plugin
       }
     }
 
+    /* Assign group array */
     $this->groupMembership = $groups_all;
+
+    /* Create an array of all grouops used by all users */
     foreach( $groups_all as $dn => $cn){
       if(isset($groups_some[$dn])){
         unset($groups_some[$dn]);
@@ -1568,6 +1700,7 @@ class posixAccount extends plugin
       $this->trustModel= "";
     }
 
+    /* Create access informations */
     $this->accessTo = array();
     if (isset($this->multi_attrs['accessTo'])){
       for ($i= 0; $i<$this->multi_attrs['accessTo']['count']; $i++){
@@ -1575,6 +1708,22 @@ class posixAccount extends plugin
         $this->accessTo[$tmp]= $tmp;
       }
     }
+
+    /* Adjust shadow checkboxes */
+    foreach (array("shadowMin", "shadowMax", "shadowWarning", "shadowInactive",
+          "shadowExpire") as $val){
+      if ($this->$val != 0){
+        $oval= "activate_".$val;
+        $this->$oval= "1";
+      }
+    }
+
+    /* Convert to seconds */
+    if(isset($this->multi_attrs['shadowExpire'])){
+      $this->shadowExpire = $this->convertToSeconds($this->multi_attrs['shadowExpire'][0]);
+    }else{
+      $this->activate_shadowExpire = FALSE;
+    }
   }