From 0110094b2d206e88dceb0cfe2bc4c85f2e826dda Mon Sep 17 00:00:00 2001
From: moglia <moglia@ispconfig3>
Date: Thu, 13 May 2010 00:39:42 -0400
Subject: [PATCH] Small brazilian portuguese language files update.  br_database_list.lng

---
 interface/web/mail/mail_domain_edit.php |   67 +++++++++++++++++++++------------
 1 files changed, 43 insertions(+), 24 deletions(-)

diff --git a/interface/web/mail/mail_domain_edit.php b/interface/web/mail/mail_domain_edit.php
index e5df386..bfd38ca 100644
--- a/interface/web/mail/mail_domain_edit.php
+++ b/interface/web/mail/mail_domain_edit.php
@@ -55,20 +55,14 @@
 		
 		// we will check only users, not admins
 		if($_SESSION["s"]["user"]["typ"] == 'user') {
-			
-			// Get the limits of the client
-			$client_group_id = $_SESSION["s"]["user"]["default_group"];
-			$client = $app->db->queryOneRecord("SELECT limit_maildomain FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
-			
-			// Check if the user may add another maildomain.
-			if($client["limit_maildomain"] >= 0) {
-				$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM mail_domain WHERE sys_groupid = $client_group_id");
-				if($tmp["number"] >= $client["limit_maildomain"]) {
-					$app->error($app->tform->wordbook["limit_maildomain_txt"]);
-				}
+			if(!$app->tform->checkClientLimit('limit_maildomain')) {
+				$app->error($app->tform->wordbook["limit_maildomain_txt"]);
+			}
+			if(!$app->tform->checkResellerLimit('limit_maildomain')) {
+				$app->error('Reseller: '.$app->tform->wordbook["limit_maildomain_txt"]);
 			}
 		}
-		
+
 		parent::onShowNew();
 	}
 	
@@ -78,7 +72,7 @@
 		if($_SESSION["s"]["user"]["typ"] == 'admin') {
 			// Getting Clients of the user
 			if($_SESSION["s"]["user"]["typ"] == 'admin') {
-				$sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0";
+				$sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0 ORDER BY name";
 			} else {
 				$client_group_id = $_SESSION["s"]["user"]["default_group"];
 				$sql = "SELECT client.client_id, limit_web_domain, default_webserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id";
@@ -86,9 +80,10 @@
 			$clients = $app->db->queryAllRecords($sql);
 			$client_select = '';
 			if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
+			$tmp_data_record = $app->tform->getDataRecord($this->id);
 			if(is_array($clients)) {
 				foreach( $clients as $client) {
-					$selected = ($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
+					$selected = ($client["groupid"] == $tmp_data_record["sys_groupid"])?'SELECTED':'';
 					$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
 				}
 			}
@@ -98,7 +93,7 @@
 
 			// Get the limits of the client
 			$client_group_id = $_SESSION["s"]["user"]["default_group"];
-			$client = $app->db->queryOneRecord("SELECT client.client_id, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			$client = $app->db->queryOneRecord("SELECT client.client_id, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id order by contact_name");
 			
 			// Set the webserver to the default server of the client
 			$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_webserver]");
@@ -108,10 +103,12 @@
 			// Fill the client select field
 			$sql = "SELECT groupid, name FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$client['client_id'];
 			$clients = $app->db->queryAllRecords($sql);
-			$client_select = '<option value="'.$client['client_id'].'">'.$client['contact_name'].'</option>';
+			$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$client['client_id']);
+			$client_select = '<option value="'.$tmp['groupid'].'">'.$client['contact_name'].'</option>';
+			$tmp_data_record = $app->tform->getDataRecord($this->id);
 			if(is_array($clients)) {
 				foreach( $clients as $client) {
-					$selected = @($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
+					$selected = @($client["groupid"] == $tmp_data_record["sys_groupid"])?'SELECTED':'';
 					$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
 				}
 			}
@@ -119,7 +116,24 @@
 
 		}
 		
-		
+		/*
+		 * Now we have to check, if we should use the domain-module to select the domain
+		 * or not
+		 */
+		$app->uses('ini_parser,getconf');
+		$settings = $app->getconf->get_global_config('domains');
+		if ($settings['use_domain_module'] == 'y'){
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$sql = "SELECT domain FROM domain WHERE sys_groupid =" . $client_group_id;
+			$domains = $app->db->queryAllRecords($sql);
+			$domain_select = '';
+			if(is_array($domains)) {
+				foreach( $domains as $domain) {
+					$domain_select .= "<option value=" . $domain['domain'] . ">" . $domain['domain'] . "</option>\r\n";
+				}
+			}
+			$app->tpl->setVar("domain_option",$domain_select);
+		}
 		
 		
 		// Get the spamfilter policys for the user
@@ -180,6 +194,11 @@
 			// Clients may not set the client_group_id, so we unset them if user is not a admin
 			if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
 		}
+		
+		//* make sure that the email domain is lowercase
+		if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
+		
+		
 		parent::onSubmit();
 	}
 	
@@ -263,7 +282,7 @@
 		if($policy_id > 0) {
 			if($tmp_user["id"] > 0) {
 				// There is already a record that we will update
-				$app->db->datalogUpdate('spamfilter_users', "policy_id = $ploicy_id", 'id', $tmp_user["id"]);
+				$app->db->datalogUpdate('spamfilter_users', "policy_id = $policy_id", 'id', $tmp_user["id"]);
 			} else {
 				$tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ".$this->id);
 				// We create a new record
@@ -278,14 +297,14 @@
 				$app->db->datalogDelete('spamfilter_users', 'id', $tmp_user["id"]);
 			}
 		} // endif spamfilter policy
-		
-		//** If the domain name has been changed, change the domain in all mailbox records
-		if($this->oldDataRecord['domain'] != $this->dataRecord['domain']) {
+		//** If the domain name or owner has been changed, change the domain and owner in all mailbox records
+		if($this->oldDataRecord['domain'] != $this->dataRecord['domain'] || (isset($this->dataRecord['client_group_id']) && $this->oldDataRecord['sys_groupid'] != $this->dataRecord['client_group_id'])) {
 			$app->uses('getconf');
 			$mail_config = $app->getconf->get_server_config($this->dataRecord["server_id"],'mail');
 			
 			//* Update the mailboxes
 			$mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like '%@".mysql_real_escape_string($this->oldDataRecord['domain'])."'");
+			$sys_groupid = (isset($this->dataRecord['client_group_id']))?$this->dataRecord['client_group_id']:$this->oldDataRecord['sys_groupid'];
 			if(is_array($mailusers)) {
 				foreach($mailusers as $rec) {
 					// setting Maildir, Homedir, UID and GID
@@ -294,7 +313,7 @@
 					$maildir = str_replace("[localpart]",$mail_parts[0],$maildir);
 					$maildir = mysql_real_escape_string($maildir);
 					$email = mysql_real_escape_string($mail_parts[0].'@'.$this->dataRecord['domain']);
-					$app->db->datalogUpdate('mail_user', "maildir = '$maildir', email = '$email'", 'mailuser_id', $rec['mailuser_id']);
+					$app->db->datalogUpdate('mail_user', "maildir = '$maildir', email = '$email', sys_groupid = '$sys_groupid'", 'mailuser_id', $rec['mailuser_id']);
 				}
 			}
 			
@@ -304,7 +323,7 @@
 				foreach($forwardings as $rec) {
 					$destination = mysql_real_escape_string(str_replace($this->oldDataRecord['domain'],$this->dataRecord['domain'],$rec['destination']));
 					$source = mysql_real_escape_string(str_replace($this->oldDataRecord['domain'],$this->dataRecord['domain'],$rec['source']));
-					$app->db->datalogUpdate('mail_forwarding', "source = '$source', destination = '$destination'", 'forwarding_id', $rec['forwarding_id']);
+					$app->db->datalogUpdate('mail_forwarding', "source = '$source', destination = '$destination', sys_groupid = '$sys_groupid'", 'forwarding_id', $rec['forwarding_id']);
 				}
 			}
 			

--
Gitblit v1.9.1