From ae171fab6ed64f83f4a6ee71f4e12a6cf0e2c70b Mon Sep 17 00:00:00 2001
From: mcramer <m.cramer@pixcept.de>
Date: Fri, 05 Oct 2012 03:46:40 -0400
Subject: [PATCH] Updated: client additional template db column had varchar(255) which was too small in some cases

---
 interface/web/mail/mail_domain_edit.php |   42 +++++++++++++++++++++++++++++++-----------
 1 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/interface/web/mail/mail_domain_edit.php b/interface/web/mail/mail_domain_edit.php
index ee7eaea..7c1d7df 100644
--- a/interface/web/mail/mail_domain_edit.php
+++ b/interface/web/mail/mail_domain_edit.php
@@ -126,7 +126,7 @@
 			/*
 			 * The admin can select ALL domains, the user only the domains assigned to him
 			 */
-			$sql = "SELECT domain FROM domain ";
+			$sql = "SELECT domain_id, domain FROM domain ";
 			if ($_SESSION["s"]["user"]["typ"] != 'admin') {
 				$sql .= "WHERE sys_groupid =" . $client_group_id;
 			}
@@ -136,11 +136,11 @@
 			if(is_array($domains) && sizeof($domains) > 0) {
 				/* We have domains in the list, so create the drop-down-list */
 				foreach( $domains as $domain) {
-					$domain_select .= "<option value=" . $domain['domain'] ;
+					$domain_select .= "<option value=" . $domain['domain_id'] ;
 					if ($domain['domain'] == $this->dataRecord["domain"]) {
 						$domain_select .= " selected";
 					}
-					$domain_select .= ">" . $domain['domain'] . "</option>\r\n";
+					$domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n";
 				}
 			}
 			else {
@@ -184,7 +184,27 @@
 
 	function onSubmit() {
 		global $app, $conf;
-		if($_SESSION["s"]["user"]["typ"] != 'admin') {
+		
+        /* check if the domain module is used - and check if the selected domain can be used! */
+		$app->uses('ini_parser,getconf');
+		$settings = $app->getconf->get_global_config('domains');
+		if ($settings['use_domain_module'] == 'y') {
+			$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
+			
+            $sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . $app->functions->intval($this->dataRecord['domain']);
+			if ($_SESSION["s"]["user"]["typ"] != 'admin') {
+				$sql .= " AND sys_groupid =" . $client_group_id;
+			}
+			$domain_check = $app->db->queryOneRecord($sql);
+            if(!$domain_check) {
+                // invalid domain selected
+                $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
+            } else {
+                $this->dataRecord['domain'] = $domain_check['domain'];
+            }
+        }
+        
+        if($_SESSION["s"]["user"]["typ"] != 'admin') {
 
 			// Get the limits of the client
 			$client_group_id = $_SESSION["s"]["user"]["default_group"];
@@ -193,7 +213,7 @@
 			// When the record is updated
 			if($this->id > 0) {
 				// restore the server ID if the user is not admin and record is edited
-				$tmp = $app->db->queryOneRecord("SELECT server_id FROM mail_domain WHERE domain_id = ".intval($this->id));
+				$tmp = $app->db->queryOneRecord("SELECT server_id FROM mail_domain WHERE domain_id = ".$app->functions->intval($this->id));
 				$this->dataRecord["server_id"] = $tmp["server_id"];
 				unset($tmp);
 				// When the record is inserted
@@ -227,16 +247,16 @@
 		// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
 		// also make sure that the user can not delete domain created by a admin
 		if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
-			$client_group_id = intval($this->dataRecord["client_group_id"]);
+			$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
 			$app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
 		}
 		if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
-			$client_group_id = intval($this->dataRecord["client_group_id"]);
+			$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
 			$app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$this->id);
 		}
 
 		// Spamfilter policy
-		$policy_id = intval($this->dataRecord["policy"]);
+		$policy_id = $app->functions->intval($this->dataRecord["policy"]);
 		if($policy_id > 0) {
 			$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".$app->db->quote($this->dataRecord["domain"])."'");
 			if($tmp_user["id"] > 0) {
@@ -287,20 +307,20 @@
 		// make sure that the record belongs to the client group and not the admin group when admin inserts it
 		// also make sure that the user can not delete domain created by a admin
 		if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
-			$client_group_id = intval($this->dataRecord["client_group_id"]);
+			$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
 			$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id");
 			$client_user_id = ($tmp['userid'] > 0)?$tmp['userid']:1;
 			$app->db->query("UPDATE mail_domain SET sys_userid = $client_user_id, sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
 		}
 		if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
-			$client_group_id = intval($this->dataRecord["client_group_id"]);
+			$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
 			$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id");
 			$client_user_id = ($tmp['userid'] > 0)?$tmp['userid']:1;
 			$app->db->query("UPDATE mail_domain SET sys_userid = $client_user_id, sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$this->id);
 		}
 
 		// Spamfilter policy
-		$policy_id = intval($this->dataRecord["policy"]);
+		$policy_id = $app->functions->intval($this->dataRecord["policy"]);
 		$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".$app->db->quote($this->dataRecord["domain"])."'");
 		if($policy_id > 0) {
 			if($tmp_user["id"] > 0) {

--
Gitblit v1.9.1