From 76a1008a5c4d6bacc000eec590006ea57c7dbb4f Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Sun, 20 May 2007 18:00:24 +0000
Subject: [PATCH] updated client form

---
 interface/lib/classes/tform.inc.php           |  7 +-
 interface/lib/classes/validate_client.inc.php | 66 +++++++++++++
 interface/web/client/client_edit.php          | 64 ++++++++++++-
 interface/web/client/form/client.tform.php    |  9 +-
 interface/web/client/lib/lang/en_client.lng   | 84 ++++++++---------
 .../client/templates/client_edit_address.htm  | 92 +++++++++++++++++++
 .../client/templates/client_edit_limits.htm   | 44 +++++++++
 7 files changed, 319 insertions(+), 47 deletions(-)
 create mode 100644 interface/lib/classes/validate_client.inc.php
 create mode 100644 interface/web/client/templates/client_edit_address.htm
 create mode 100644 interface/web/client/templates/client_edit_limits.htm

diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php
index 0fed37fc41..d8c58a3ceb 100644
--- a/interface/lib/classes/tform.inc.php
+++ b/interface/lib/classes/tform.inc.php
@@ -104,10 +104,11 @@ class tform {
         var $errorMessage = '';
 
         var $dateformat = "d.m.Y";
-    var $formDef;
+    	var $formDef;
         var $wordbook;
         var $module;
         var $primary_id;
+		var $diffrec = array();
 
         /**
         * Laden der Tabellendefinition
@@ -611,7 +612,7 @@ class tform {
                                                 $validator_class = $validator['class'];
                                                 $validator_function = $validator['function'];
                                                 $app->uses($validator_class);
-                                                $this->errorMessage .= $app->$validator_class->$validator_function($validator);
+                                                $this->errorMessage .= $app->$validator_class->$validator_function($field_name, $field_value, $validator);
                                         } else {
                                                 $this->errorMessage .= "Custom validator class or function is empty<br>\r\n";
                                         }
@@ -852,6 +853,8 @@ class tform {
 				
 				// Insert the server_id, if the record has a server_id
 				$server_id = ($record_old["server_id"] > 0)?$record_old["server_id"]:0;
+				
+				$this->diffrec = $diffrec;
 
                 if(count($diffrec) > 0) {
                         
diff --git a/interface/lib/classes/validate_client.inc.php b/interface/lib/classes/validate_client.inc.php
new file mode 100644
index 0000000000..a7b7ae8b06
--- /dev/null
+++ b/interface/lib/classes/validate_client.inc.php
@@ -0,0 +1,66 @@
+<?php
+
+/*
+Copyright (c) 2007, Till Brehm, Falko Timme, projektfarm Gmbh
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name of ISPConfig nor the names of its contributors
+      may be used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+class validate_client {
+	
+	/*
+		Validator function to check if a username is unique.
+	*/
+	function username_unique($field_name, $field_value, $validator) {
+		global $app;
+		
+		if($app->tform->action == 'NEW') {
+        	$num_rec = $app->db->queryOneRecord("SELECT count(*) as number FROM sys_user WHERE username = '".$app->db->quote($field_value)."'");
+            	if($num_rec["number"] > 0) {
+                	$errmsg = $validator['errmsg'];
+					if(isset($this->wordbook[$errmsg])) {
+                    	return $app->tform->wordbook[$errmsg]."<br>\r\n";
+					} else {
+						return $errmsg."<br>\r\n";
+					}
+                }
+        } else {
+        	$num_rec = $app->db->queryOneRecord("SELECT count(*) as number FROM sys_user WHERE username = '".$app->db->quote($field_value)."' AND client_id != ".$app->tform->primary_id);
+			if($num_rec["number"] > 0) {
+            	$errmsg = $validator['errmsg'];
+                if(isset($app->tform->wordbook[$errmsg])) {
+                	return $app->tform->wordbook[$errmsg]."<br>\r\n";
+				} else {
+					return $errmsg."<br>\r\n";
+				}
+			}
+		}
+	}
+	
+	
+	
+	
+}
\ No newline at end of file
diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php
index d66d6121d5..68b8d3a0a5 100644
--- a/interface/web/client/client_edit.php
+++ b/interface/web/client/client_edit.php
@@ -49,8 +49,68 @@ if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"]))
 
 // Loading classes
 $app->uses('tpl,tform,tform_actions');
+$app->load('tform_actions');
 
-// let tform_actions handle the page
-$app->tform_actions->onLoad();
+class page_action extends tform_actions {
+	
+	/*
+	 This function is called automatically right after
+	 the data was successful inserted in the database.
+	*/
+	function onAfterInsert() {
+		global $app;
+		// Create the group for the client
+		$sql = "INSERT INTO sys_group (name,description,client_id) VALUES ('".addslashes($this->dataRecord["username"])."','',".$this->id.")";
+		$app->db->query($sql);
+		$groupid = $app->db->insertID();
+		
+		$username = addslashes($this->dataRecord["username"]);
+		$password = addslashes($this->dataRecord["password"]);
+		$modules = 'mail';
+		$startmodule = 'mail';
+		$usertheme = addslashes($this->dataRecord["usertheme"]);
+		$type = 'user';
+		$active = 1;
+		$language = addslashes($this->dataRecord["language"]);
+		
+		// Create the controlpaneluser for the client
+		$sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)
+		VALUES ('$username',md5('$password'),'$modules','$startmodule','$usertheme','$type','$active','$language',$groupid,$groupid,".$this->id.")";
+		$app->db->query($sql);
+	}
+	
+	
+	/*
+	 This function is called automatically right after
+	 the data was successful updated in the database.
+	*/
+	function onAfterUpdate() {
+		global $app;
+		
+		// username changed
+		if(isset($app->tform->diffrec['username'])) {
+			$username = addslashes($this->dataRecord["username"]);
+			$client_id = $this->id;
+			$sql = "UPDATE sys_user SET username = '$username' WHERE client_id = $client_id";
+			$app->db->query($sql);
+			$sql = "UPDATE sys_group SET name = '$username' WHERE client_id = $client_id";
+			$app->db->query($sql);
+		}
+		
+		// password changed
+		if($this->dataRecord["password"] != '') {
+			$password = addslashes($this->dataRecord["password"]);
+			$sql = "UPDATE sys_user SET passwort = md5('$password') WHERE client_id = $client_id";
+		}
+		
+		
+		
+	}
+	
+	
+}
+
+$page = new page_action;
+$page->onLoad();
 
 ?>
\ No newline at end of file
diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php
index 491d01054d..d783d2ff68 100644
--- a/interface/web/client/form/client.tform.php
+++ b/interface/web/client/form/client.tform.php
@@ -86,6 +86,13 @@ $form["tabs"]['address'] = array (
 		'username' => array (
 			'datatype'	=> 'VARCHAR',
 			'formtype'	=> 'TEXT',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'NOTEMPTY',
+														'errmsg'=> 'username_error_empty'),
+										1 => array (	'type'	=> 'CUSTOM',
+														'class' => 'validate_client',
+														'function' => 'username_unique',
+														'errmsg'=> 'username_error_unique'),
+										),
 			'default'	=> '',
 			'value'		=> '',
 			'separator'	=> '',
@@ -120,7 +127,7 @@ $form["tabs"]['address'] = array (
 			'datatype'	=> 'VARCHAR',
 			'formtype'	=> 'SELECT',
 			'default'	=> 'default',
-			'value'		=> array('default' => 'default','grey' => 'grey'),
+			'value'		=> array('default' => 'default'),
 			'separator'	=> '',
 			'width'		=> '30',
 			'maxlength'	=> '255',
diff --git a/interface/web/client/lib/lang/en_client.lng b/interface/web/client/lib/lang/en_client.lng
index 0accf4bd93..a4717854cf 100644
--- a/interface/web/client/lib/lang/en_client.lng
+++ b/interface/web/client/lib/lang/en_client.lng
@@ -1,43 +1,43 @@
-<?php
-$wb["username_txt"] = 'Username';
-$wb["password_txt"] = 'Password';
-$wb["language_txt"] = 'Language';
-$wb["usertheme_txt"] = 'Theme';
-$wb["btn_save_txt"] = 'Save';
-$wb["btn_cancel_txt"] = 'Cancel';
-$wb["limit_maildomain_txt"] = 'Max. number of email domains';
-$wb["limit_mailbox_txt"] = 'Max. number of mailboxes';
-$wb["limit_mailalias_txt"] = 'Max. number of email aliases and redirects';
-$wb["limit_mailcatchall_txt"] = 'Max. number of email catchall accounts';
-$wb["limit_mailrouting_txt"] = 'Max. number of email routes';
-$wb["limit_mailfilter_txt"] = 'Max. number of email filters';
-$wb["limit_fetchmail_txt"] = 'Max. number of fetchmail accounts';
-$wb["limit_mailquota_txt"] = 'Mailbox quota';
-$wb["company_name_txt"] = 'Company name';
-$wb["contact_name_txt"] = 'Contact name';
-$wb["street_txt"] = 'Street';
-$wb["zip_txt"] = 'ZIP';
-$wb["city_txt"] = 'City';
-$wb["state_txt"] = 'State';
-$wb["country_txt"] = 'Country';
-$wb["telephone_txt"] = 'Telephone';
-$wb["mobile_txt"] = 'Mobile';
-$wb["fax_txt"] = 'Fax';
-$wb["email_txt"] = 'Email';
-$wb["internet_txt"] = 'Internet';
-$wb["icq_txt"] = 'ICQ';
-$wb["notes_txt"] = 'Notes';
-$wb["company_txt"] = 'Company';
-$wb["title_txt"] = 'Title';
-$wb["firstname_txt"] = 'Firstname';
-$wb["surname_txt"] = 'Surname';
-$wb["limit_client_txt"] = 'limit_client';
-$wb["limit_domain_txt"] = 'limit_domain';
-$wb["limit_subdomain_txt"] = 'limit_subdomain';
-$wb["limit_webquota_txt"] = 'limit_webquota';
-$wb["limit_database_txt"] = 'limit_database';
-$wb["ip_address_txt"] = 'ip_address';
-$wb["limit_client_error_notint"] = 'Client Limit is not a number.';
-$wb["firstname_error_empty"] = 'Firstname is empty.';
-$wb["contact_error_empty"] = 'Contact name is empty.';
+<?php
+$wb["limit_maildomain_txt"] = 'Max. number of email domains';
+$wb["limit_mailbox_txt"] = 'Max. number of mailboxes';
+$wb["limit_mailalias_txt"] = 'Max. number of email aliases and redirects';
+$wb["limit_mailcatchall_txt"] = 'Max. number of email catchall accounts';
+$wb["limit_mailrouting_txt"] = 'Max. number of email routes';
+$wb["limit_mailfilter_txt"] = 'Max. number of email filters';
+$wb["limit_fetchmail_txt"] = 'Max. number of fetchmail accounts';
+$wb["limit_mailquota_txt"] = 'Mailbox quota';
+$wb["btn_save_txt"] = 'Save';
+$wb["btn_cancel_txt"] = 'Cancel';
+$wb["company_name_txt"] = 'Company name';
+$wb["contact_name_txt"] = 'Contact name';
+$wb["username_txt"] = 'Username';
+$wb["password_txt"] = 'Password';
+$wb["language_txt"] = 'Language';
+$wb["usertheme_txt"] = 'Theme';
+$wb["street_txt"] = 'Street';
+$wb["zip_txt"] = 'ZIP';
+$wb["city_txt"] = 'City';
+$wb["state_txt"] = 'State';
+$wb["country_txt"] = 'Country';
+$wb["telephone_txt"] = 'Telephone';
+$wb["mobile_txt"] = 'Mobile';
+$wb["fax_txt"] = 'Fax';
+$wb["email_txt"] = 'Email';
+$wb["internet_txt"] = 'Internet';
+$wb["icq_txt"] = 'ICQ';
+$wb["notes_txt"] = 'Notes';
+$wb["company_txt"] = 'Company';
+$wb["title_txt"] = 'Title';
+$wb["firstname_txt"] = 'Firstname';
+$wb["surname_txt"] = 'Surname';
+$wb["limit_client_txt"] = 'limit_client';
+$wb["limit_domain_txt"] = 'limit_domain';
+$wb["limit_subdomain_txt"] = 'limit_subdomain';
+$wb["limit_webquota_txt"] = 'limit_webquota';
+$wb["limit_database_txt"] = 'limit_database';
+$wb["ip_address_txt"] = 'ip_address';
+$wb["limit_client_error_notint"] = 'Client Limit is not a number.';
+$wb["firstname_error_empty"] = 'Firstname is empty.';
+$wb["contact_error_empty"] = 'Contact name is empty.';
 ?>
\ No newline at end of file
diff --git a/interface/web/client/templates/client_edit_address.htm b/interface/web/client/templates/client_edit_address.htm
new file mode 100644
index 0000000000..499e230b99
--- /dev/null
+++ b/interface/web/client/templates/client_edit_address.htm
@@ -0,0 +1,92 @@
+<table width="500" border="0" cellspacing="0" cellpadding="2">
+  <tr>
+    <td class="frmText11">{tmpl_var name='company_name_txt'}:</td>
+    <td class="frmText11"><input name="company_name" type="text" class="text" value="{tmpl_var name='company_name'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='contact_name_txt'}:</td>
+    <td class="frmText11"><input name="contact_name" type="text" class="text" value="{tmpl_var name='contact_name'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='username_txt'}:</td>
+    <td class="frmText11"><input name="username" type="text" class="text" value="{tmpl_var name='username'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='password_txt'}:</td>
+    <td class="frmText11"><input name="password" type="password" class="text" value="{tmpl_var name='password'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='language_txt'}:</td>
+    <td class="frmText11">
+		<select name="language" class="text">
+			{tmpl_var name='language'}
+		</select>
+	</td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='usertheme_txt'}:</td>
+    <td class="frmText11">
+		<select name="usertheme" class="text">
+			{tmpl_var name='usertheme'}
+		</select>
+	</td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='street_txt'}:</td>
+    <td class="frmText11"><input name="street" type="text" class="text" value="{tmpl_var name='street'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='zip_txt'}:</td>
+    <td class="frmText11"><input name="zip" type="text" class="text" value="{tmpl_var name='zip'}" size="10" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='city_txt'}:</td>
+    <td class="frmText11"><input name="city" type="text" class="text" value="{tmpl_var name='city'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='state_txt'}:</td>
+    <td class="frmText11"><input name="state" type="text" class="text" value="{tmpl_var name='state'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='country_txt'}:</td>
+    <td class="frmText11"><input name="country" type="text" class="text" value="{tmpl_var name='country'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='telephone_txt'}:</td>
+    <td class="frmText11"><input name="telephone" type="text" class="text" value="{tmpl_var name='telephone'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='mobile_txt'}:</td>
+    <td class="frmText11"><input name="mobile" type="text" class="text" value="{tmpl_var name='mobile'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='fax_txt'}:</td>
+    <td class="frmText11"><input name="fax" type="text" class="text" value="{tmpl_var name='fax'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='email_txt'}:</td>
+    <td class="frmText11"><input name="email" type="text" class="text" value="{tmpl_var name='email'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='internet_txt'}:</td>
+    <td class="frmText11"><input name="internet" type="text" class="text" value="{tmpl_var name='internet'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='icq_txt'}:</td>
+    <td class="frmText11"><input name="icq" type="text" class="text" value="{tmpl_var name='icq'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='notes_txt'}:</td>
+    <td class="frmText11"><textarea name='notes' cols='30' rows='10'>{tmpl_var name='notes'}</textarea></td>
+  </tr>  <tr>
+    <td class="frmText11">&nbsp;</td>
+    <td class="frmText11">&nbsp;</td>
+  </tr>
+  <tr>
+    <td>&nbsp;</td>
+    <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','client/client_edit.php');"><div class="buttonEnding"></div>&nbsp;
+      <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('client/client_list.php');"><div class="buttonEnding"></div>
+    </td>
+  </tr>
+</table>
+<input type="hidden" name="id" value="{tmpl_var name='id'}">
\ No newline at end of file
diff --git a/interface/web/client/templates/client_edit_limits.htm b/interface/web/client/templates/client_edit_limits.htm
new file mode 100644
index 0000000000..11ded7394d
--- /dev/null
+++ b/interface/web/client/templates/client_edit_limits.htm
@@ -0,0 +1,44 @@
+<table width="500" border="0" cellspacing="0" cellpadding="2">
+  <tr>
+    <td class="frmText11" width="280">{tmpl_var name='limit_maildomain_txt'}:</td>
+    <td class="frmText11" width="220"><input name="limit_maildomain" type="text" class="text" value="{tmpl_var name='limit_maildomain'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='limit_mailbox_txt'}:</td>
+    <td class="frmText11"><input name="limit_mailbox" type="text" class="text" value="{tmpl_var name='limit_mailbox'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='limit_mailalias_txt'}:</td>
+    <td class="frmText11"><input name="limit_mailalias" type="text" class="text" value="{tmpl_var name='limit_mailalias'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='limit_mailcatchall_txt'}:</td>
+    <td class="frmText11"><input name="limit_mailcatchall" type="text" class="text" value="{tmpl_var name='limit_mailcatchall'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='limit_mailrouting_txt'}:</td>
+    <td class="frmText11"><input name="limit_mailrouting" type="text" class="text" value="{tmpl_var name='limit_mailrouting'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='limit_mailfilter_txt'}:</td>
+    <td class="frmText11"><input name="limit_mailfilter" type="text" class="text" value="{tmpl_var name='limit_mailfilter'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='limit_fetchmail_txt'}:</td>
+    <td class="frmText11"><input name="limit_fetchmail" type="text" class="text" value="{tmpl_var name='limit_fetchmail'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='limit_mailquota_txt'}:</td>
+    <td class="frmText11"><input name="limit_mailquota" type="text" class="text" value="{tmpl_var name='limit_mailquota'}" size="10" maxlength="10"> MB</td>
+  </tr>  <tr>
+    <td class="frmText11">&nbsp;</td>
+    <td class="frmText11">&nbsp;</td>
+  </tr>
+  <tr>
+    <td>&nbsp;</td>
+    <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','client/client_edit.php');"><div class="buttonEnding"></div>&nbsp;
+      <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('client/client_list.php');"><div class="buttonEnding"></div>
+    </td>
+  </tr>
+</table>
+<input type="hidden" name="id" value="{tmpl_var name='id'}">
\ No newline at end of file
-- 
GitLab