users_edit.php 5.68 KB
Newer Older
tbrehm's avatar
tbrehm committed
1
2
<?php
/*
3
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
tbrehm's avatar
tbrehm committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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.
*/
29

tbrehm's avatar
tbrehm committed
30
31
32
33
34
35
36
37
38
39
40

/******************************************
* Begin Form configuration
******************************************/

$tform_def_file = "form/users.tform.php";

/******************************************
* End Form configuration
******************************************/

41
42
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
43

44
45
//* Check permissions for module
$app->auth->check_module_permissions('admin');
tbrehm's avatar
tbrehm committed
46

47
48
// Loading classes
$app->uses('tpl,tform,tform_actions');
49
$app->load('tform_actions');
tbrehm's avatar
tbrehm committed
50

51
class page_action extends tform_actions {
52

53
54
	function onBeforeInsert() {
		global $app, $conf;
55
56
57
58
59
		
		//* Security settings check
		if(isset($this->dataRecord['typ']) && $this->dataRecord['typ'][0] == 'admin') {
			$app->auth->check_security_permissions('admin_allow_new_admin');
		}
60
61

		if(!in_array($this->dataRecord['startmodule'], $this->dataRecord['modules'])) {
62
63
			$app->tform->errorMessage .= $app->tform->wordbook['startmodule_err'];
		}
64
		
65
66
67
68
		//* Do not add users here
		if(isset($this->dataRecord['typ']) && $this->dataRecord['typ'][0] == 'user') {
			$app->tform->errorMessage .= $app->tform->wordbook['no_user_insert'];
		}
69
		
70
	}
71

72
73
	function onBeforeUpdate() {
		global $app, $conf;
74

75
		if($conf['demo_mode'] == true && $_REQUEST['id'] <= 3) $app->error('This function is disabled in demo mode.');
Till Brehm's avatar
Till Brehm committed
76

77
78
79
80
		//* Security settings check
		if(isset($this->dataRecord['typ']) && $this->dataRecord['typ'][0] == 'admin') {
			$app->auth->check_security_permissions('admin_allow_new_admin');
		}
81
82

		if(@is_array($this->dataRecord['modules']) && !in_array($this->dataRecord['startmodule'], $this->dataRecord['modules'])) {
83
84
			$app->tform->errorMessage .= $app->tform->wordbook['startmodule_err'];
		}
85
		
86
		$this->oldDataRecord = $app->tform->getDataRecord($this->id);
87
88
89
90
91
92
		
		//* A user that belongs to a client record (client or reseller) may not have typ admin
		if(isset($this->dataRecord['typ']) && $this->dataRecord['typ'][0] == 'admin'  && $this->oldDataRecord['client_id'] > 0) {
			$app->tform->errorMessage .= $app->tform->wordbook['client_not_admin_err'];
		}
		
93
94
95
96
97
		//* Users have to belong to clients
		if(isset($this->dataRecord['typ']) && $this->dataRecord['typ'][0] == 'user'  && $this->oldDataRecord['client_id'] == 0) {
			$app->tform->errorMessage .= $app->tform->wordbook['no_user_insert'];
		}
		
98
	}
99

100
101
102
103
104
105
	/*
	 This function is called automatically right after
	 the data was successful updated in the database.
	*/
	function onAfterUpdate() {
		global $app, $conf;
106

107
108
		$app->uses('auth');
		
109
		$client = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE userid = ?", $this->id);
Till Brehm's avatar
Till Brehm committed
110
		$client_id = $app->functions->intval($client['client_id']);
111
112
		$username = $this->dataRecord["username"];
		$old_username = $this->oldDataRecord['username'];
113
114
115

		// username changed
		if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord['username']) && $this->dataRecord['username'] != '' && $this->oldDataRecord['username'] != $this->dataRecord['username']) {
116
117
118
			$sql = "UPDATE client SET username = ? WHERE client_id = ? AND username = ?";
			$app->db->query($sql, $username, $client_id, $old_username);
			$tmp = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE client_id = ?", $client_id);
119
			$app->db->datalogUpdate("sys_group", array("name" => $username), 'groupid', $tmp['groupid']);
120
121
			unset($tmp);
		}
122

123
124
		// password changed
		if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord["passwort"]) && $this->dataRecord["passwort"] != '') {
125
			$password = $this->dataRecord["passwort"];
126
			$password = $app->auth->crypt_password($password);
127
128
			$sql = "UPDATE client SET password = ? WHERE client_id = ? AND username = ?";
			$app->db->query($sql, $password, $client_id, $username);
129
		}
130

131
132
		// language changed
		if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord['language']) && $this->dataRecord['language'] != '' && $this->oldDataRecord['language'] != $this->dataRecord['language']) {
133
			$language = $this->dataRecord["language"];
134
135
			$sql = "UPDATE client SET language = ? WHERE client_id = ? AND username = ?";
			$app->db->query($sql, $language, $client_id, $username);
136
		}
137

138
		parent::onAfterUpdate();
139
	}
140
141
142
143
144

}

$page = new page_action;
$page->onLoad();
tbrehm's avatar
tbrehm committed
145

146
?>