Till Brehm
2014-08-14 9edea9976bd605071e0694a90d704266c0b7e0f9
commit | author | age
b5a2f8 1 <?php
T 2 /*
c4ff82 3 Copyright (c) 2008, Till Brehm, projektfarm Gmbh
b5a2f8 4 All rights reserved.
T 5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
cf71a4 29
b5a2f8 30
T 31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/users.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
7fe908 41 require_once '../../lib/config.inc.php';
MC 42 require_once '../../lib/app.inc.php';
cf71a4 43
910093 44 //* Check permissions for module
T 45 $app->auth->check_module_permissions('admin');
b5a2f8 46
cf71a4 47 // Loading classes
T 48 $app->uses('tpl,tform,tform_actions');
c4ff82 49 $app->load('tform_actions');
b5a2f8 50
c4ff82 51 class page_action extends tform_actions {
7fe908 52
c4ff82 53     function onBeforeInsert() {
T 54         global $app, $conf;
9edea9 55         
TB 56         //* Security settings check
57         if(isset($this->dataRecord['typ']) && $this->dataRecord['typ'][0] == 'admin') {
58             $app->auth->check_security_permissions('admin_allow_new_admin');
59         }
7fe908 60
MC 61         if(!in_array($this->dataRecord['startmodule'], $this->dataRecord['modules'])) {
c4ff82 62             $app->tform->errorMessage .= $app->tform->wordbook['startmodule_err'];
T 63         }
9edea9 64         
TB 65         
66         
c4ff82 67     }
7fe908 68
b998c5 69     function onBeforeUpdate() {
T 70         global $app, $conf;
7fe908 71
91624b 72         if($conf['demo_mode'] == true && $_REQUEST['id'] <= 3) $app->error('This function is disabled in demo mode.');
9edea9 73         
TB 74         //* Security settings check
75         if(isset($this->dataRecord['typ']) && $this->dataRecord['typ'][0] == 'admin') {
76             $app->auth->check_security_permissions('admin_allow_new_admin');
77         }
7fe908 78
MC 79         if(@is_array($this->dataRecord['modules']) && !in_array($this->dataRecord['startmodule'], $this->dataRecord['modules'])) {
b998c5 80             $app->tform->errorMessage .= $app->tform->wordbook['startmodule_err'];
T 81         }
132df2 82         
bfcdef 83         $this->oldDataRecord = $app->tform->getDataRecord($this->id);
132df2 84         
TB 85         //* A user that belongs to a client record (client or reseller) may not have typ admin
86         if(isset($this->dataRecord['typ']) && $this->dataRecord['typ'][0] == 'admin'  && $this->oldDataRecord['client_id'] > 0) {
87             $app->tform->errorMessage .= $app->tform->wordbook['client_not_admin_err'];
88         }
89         
bfcdef 90     }
7fe908 91
bfcdef 92     /*
T 93      This function is called automatically right after
94      the data was successful updated in the database.
95     */
96     function onAfterUpdate() {
97         global $app, $conf;
7fe908 98
bfcdef 99         $client = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE userid = ".$this->id);
604c0c 100         $client_id = $app->functions->intval($client['client_id']);
bfcdef 101         $username = $app->db->quote($this->dataRecord["username"]);
T 102         $old_username = $app->db->quote($this->oldDataRecord['username']);
103
104         // username changed
105         if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord['username']) && $this->dataRecord['username'] != '' && $this->oldDataRecord['username'] != $this->dataRecord['username']) {
106             $sql = "UPDATE client SET username = '$username' WHERE client_id = $client_id AND username = '$old_username'";
107             $app->db->query($sql);
108             $tmp = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE client_id = $client_id");
109             $app->db->datalogUpdate("sys_group", "name = '$username'", 'groupid', $tmp['groupid']);
110             unset($tmp);
111         }
7fe908 112
bfcdef 113         // password changed
T 114         if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord["passwort"]) && $this->dataRecord["passwort"] != '') {
115             $password = $app->db->quote($this->dataRecord["passwort"]);
116             $salt="$1$";
117             $base64_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
118             for ($n=0;$n<8;$n++) {
7fe908 119                 $salt.=$base64_alphabet[mt_rand(0, 63)];
bfcdef 120             }
T 121             $salt.="$";
7fe908 122             $password = crypt(stripslashes($password), $salt);
bfcdef 123             $sql = "UPDATE client SET password = '$password' WHERE client_id = $client_id AND username = '$username'";
T 124             $app->db->query($sql);
125         }
7fe908 126
bfcdef 127         // language changed
T 128         if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord['language']) && $this->dataRecord['language'] != '' && $this->oldDataRecord['language'] != $this->dataRecord['language']) {
129             $language = $app->db->quote($this->dataRecord["language"]);
130             $sql = "UPDATE client SET language = '$language' WHERE client_id = $client_id AND username = '$username'";
131             $app->db->query($sql);
132         }
7fe908 133
bfcdef 134         // reseller status changed
T 135         /*
136         if(isset($this->dataRecord["limit_client"]) && $this->dataRecord["limit_client"] != $this->oldDataRecord["limit_client"]) {
137             $modules = $conf['interface_modules_enabled'];
138             if($this->dataRecord["limit_client"] > 0) $modules .= ',client';
139             $modules = $app->db->quote($modules);
140             $client_id = $this->id;
141             $sql = "UPDATE sys_user SET modules = '$modules' WHERE client_id = $client_id";
142             $app->db->query($sql);
143         }
144         */
145         parent::onAfterUpdate();
b998c5 146     }
c4ff82 147
T 148 }
149
150 $page = new page_action;
151 $page->onLoad();
b5a2f8 152
7fe908 153 ?>