Code

Multiple edit
[gosa.git] / gosa-core / plugins / personal / samba / class_sambaAccount.inc
index bd71c8f7ae27eccddaee0e3891d5c1519dfc7e6e..4de21f4935a1f8635de40597eb705cd965fbd137 100644 (file)
@@ -91,6 +91,11 @@ class sambaAccount extends plugin
   var $uid= "";
   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
 
+  var $multiple_support = TRUE;
+  /* Only used  for multiple edit */
+  var $temporary_disable = FALSE;
+  var $no_password_required = FALSE;
+
   function sambaAccount (&$config, $dn= NULL)
   {
     /* Load attributes depending on the samba version */
@@ -213,28 +218,31 @@ class sambaAccount extends plugin
       return ($display);
     }
 
-    /* Show tab dialog headers */
-    $display= "";
-    if ($this->parent !== NULL){
-      if ($this->is_account){
-        $display= $this->show_disable_header(_("Remove samba account"),
-            _("This account has samba features enabled. You can disable them by clicking below."));
-      } else {
-        $obj= $this->parent->by_object['posixAccount'];
-
-        /* Samba3 dependency on posix accounts are enabled
-           in the moment, because I need to rely on unique
-           uidNumbers. There'll be a better solution later
-           on. */
-        if ($obj->is_account){
+    $display ="";
+    if(!$this->multiple_support_active){
 
-          $display= $this->show_enable_header(_("Create samba account"),
-              _("This account has samba features disabled. You can enable them by clicking below."));
+      /* Show tab dialog headers */
+      $display= "";
+      if ($this->parent !== NULL){
+        if ($this->is_account){
+          $display= $this->show_disable_header(_("Remove samba account"),
+              _("This account has samba features enabled. You can disable them by clicking below."));
         } else {
-          $display= $this->show_enable_header(_("Create samba account"),
-              _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
+          $obj= $this->parent->by_object['posixAccount'];
+
+          /* Samba3 dependency on posix accounts are enabled
+             in the moment, because I need to rely on unique
+             uidNumbers. There'll be a better solution later
+             on. */
+          if ($obj->is_account){
+            $display= $this->show_enable_header(_("Create samba account"),
+                _("This account has samba features disabled. You can enable them by clicking below."));
+          } else {
+            $display= $this->show_enable_header(_("Create samba account"),
+                _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
+          }
+          return ($display);
         }
-        return ($display);
       }
     }
 
@@ -626,7 +634,30 @@ class sambaAccount extends plugin
       }
     }
 
+
+    foreach($this->attributes as $attr){
+      if(in_array($attr,$this->multi_boxes)){
+        $smarty->assign("use_".$attr,TRUE);
+      }else{
+        $smarty->assign("use_".$attr,FALSE);
+      }
+    }
+    foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
+          "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
+          "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
+          "onnectclientprinters","defaultprinter","shadow","brokenconn",
+          "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable", 
+          "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
+          "workstation_list") as $attr){
+      if(in_array($attr,$this->multi_boxes)){
+        $smarty->assign("use_".$attr,TRUE);
+      }else{
+        $smarty->assign("use_".$attr,FALSE);
+      }
+    }
+
     /* Show main page */
+    $smarty->assign("multiple_support",$this->multiple_support_active);
     if ($this->samba3){
       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
     } else {
@@ -742,9 +773,11 @@ class sambaAccount extends plugin
         $this->sambaPwdCanChange= $tmp;
       }
       $tmp= "UX";
+      $this->no_password_required = FALSE;
       if (isset($_POST["no_password_required"])){
         if ($_POST["no_password_required"] == 1){
           $tmp.= "N";
+          $this->no_password_required = TRUE;
         }
       }
       if (isset($_POST["password_expires"])){
@@ -754,8 +787,10 @@ class sambaAccount extends plugin
       } else {
         $this->password_expires= 0;
       }
+      $this->temporary_disable = FALSE;
       if (isset($_POST["temporary_disable"])){
         if ($_POST["temporary_disable"] == 1){
+          $this->temporary_disable = TRUE;
           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
             $tmp.= "L";
           } else {
@@ -1136,6 +1171,220 @@ class sambaAccount extends plugin
             "sambaUserWorkstations" => _("Allow connection from")))
               );
   }    
+
+  function enable_multiple_support()
+  {
+    plugin::enable_multiple_support();
+    if($this->samba3){
+      $this->multiple_support_active = TRUE;
+    }else{
+      $this->multiple_support_active = FALSE;
+    }
+  } 
+
+  function multiple_save_object()
+  {
+    $this->save_object();
+    plugin::multiple_save_object();
+    foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
+          "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
+          "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
+          "onnectclientprinters","defaultprinter","shadow","brokenconn",
+          "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
+          "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
+          "workstation_list") as $attr){
+      if(isset($_POST["use_".$attr])){
+        $this->multi_boxes[] = $attr;
+      }
+    }
+  }
+
+  function multiple_execute()
+  {
+    return($this->execute());
+  } 
+
+  function get_multi_edit_values()
+  {
+    $ret = plugin::get_multi_edit_values();
+
+    /* Terminal Server  */
+    if(in_array("tslogin",$this->multi_boxes)){
+      $ret['tslogin'] = $this->mungedObject->getTsLogin();
+    }
+    if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
+      $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
+    }
+    if(in_array("CtxWFHomeDir",$this->multi_boxes)){
+      $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
+    }
+    if(in_array("CtxWFProfilePath",$this->multi_boxes)){
+      $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
+    }
+
+    if(in_array("inherit",$this->multi_boxes)){
+      $ret['inherit'] = $this->mungedObject->getInheritMode();
+    }       
+    if(in_array("CtxInitialProgram",$this->multi_boxes)){
+      $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
+    } 
+    if(in_array("CtxWorkDirectory",$this->multi_boxes)){
+      $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
+    } 
+
+    /* Time Limits. Be careful here, there are some negations  */
+    if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
+      $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
+      if(!$ret["CtxMaxConnectionTimeF"]){
+        $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
+      }
+    }
+    if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
+      $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
+      if(!$ret["CtxMaxDisconnectionTimeF"]){
+        $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
+      }
+    }
+    if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
+      $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
+      if(!$ret["CtxMaxIdleTimeF"]){
+        $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
+      }
+    }
+
+    /* Client Devices */
+    if(in_array("connectclientdrives",$this->multi_boxes)){
+      $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
+    }
+    if(in_array("connectclientprinters",$this->multi_boxes)){
+      $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
+    }
+    if(in_array("defaultprinter",$this->multi_boxes)){
+      $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
+    }
+
+    /* Misc */
+    if(in_array("shadow",$this->multi_boxes)){
+      $ret["shadow"]    =$this->mungedObject->getShadow();
+    }
+    if(in_array("brokenconn",$this->multi_boxes)){
+      $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
+    }
+    if(in_array("reconn",$this->multi_boxes)){
+      $ret["reconn"]    =$this->mungedObject->getReConn();
+    }
+
+    /* Flags */
+    if(in_array("allow_pwchange",$this->multi_boxes)){
+      $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
+      $ret['pwdCanChange']      = $this->pwdCanChange;
+    }
+  
+    if(in_array("password_expires",$this->multi_boxes)){
+      $ret['password_expires']  = $this->password_expires;
+      $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
+    }
+    if(in_array("logon_time_set",$this->multi_boxes)){
+      $ret['logon_time_set'] = $this->logon_time_set;
+      $ret['sambaLogonTime'] = $this->sambaLogonTime;
+    }
+    if(in_array("logoff_time_set",$this->multi_boxes)){
+      $ret['logoff_time_set'] = $this->logoff_time_set;
+      $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
+    }
+    if(in_array("kickoff_time_set",$this->multi_boxes)){
+      $ret['kickoff_time_set'] = $this->kickoff_time_set;
+      $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
+    }
+
+    if(in_array("no_password_required",$this->multi_boxes)){
+      $ret['no_password_required'] = $this->no_password_required;
+    }
+
+    if(in_array("temporary_disable",$this->multi_boxes)){
+      $ret['temporary_disable'] = $this->temporary_disable;
+    }
+
+    return($ret);
+  }
+
+  function set_multi_edit_values($values)
+  {
+    plugin::set_multi_edit_values($values);
+
+    /* Enable disabled terminal login, this is inverted somehow */
+    if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
+  
+    /* Imherit client configuration */
+    if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
+  
+    /* Get all ctx values posted */
+    $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
+                 "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
+    foreach($ctx as $attr){
+      if(isset($values[$attr])){
+        $this->mungedObject->ctx[$attr] = $values[$attr] ;
+      }
+    }
+
+    if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
+    if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
+    if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
+
+    if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
+    if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
+    if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
+
+    if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
+    if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
+    if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
+
+  
+    if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
+    if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
+
+    
+    
+
+    if(isset($values['password_expires'])){
+      $this->password_expires = $values['password_expires'];
+      $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
+    }
+    if(isset($values['logon_time_set'])){
+      $this->logon_time_set = $values['logon_time_set'];
+      $this->sambaLogonTime = $values['sambaLogonTime'];
+    }
+    if(isset($values['logoff_time_set'])){
+      $this->logoff_time_set = $values['logoff_time_set'];
+      $this->sambaLogoffTime = $values['sambaLogoffTime'];
+    }
+    if(isset($values['kickoff_time_set'])){
+      $this->kickoff_time_set = $values['kickoff_time_set'];
+      $this->sambaKickoffTime = $values['sambaKickoffTime'];
+    }
+
+    if(isset($values['no_password_required'])){
+      if($values['no_password_required']){
+        if(!preg_match("/N/",$this->sambaAcctFlags)) {
+          $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
+        }
+      }else{
+        $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
+      }
+    }      
+
+    if(isset($values['temporary_disable'])){
+      if($values['temporary_disable']){
+        if(preg_match("/L/",$this->sambaAcctFlags)) {
+          // Keep L
+        }else{
+          $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
+        }
+      }else{
+        $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
+      }
+    }
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: