Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
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.');
1ed92e 73
9edea9 74         //* Security settings check
TB 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
cc7a82 99         $client = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE userid = ?", $this->id);
604c0c 100         $client_id = $app->functions->intval($client['client_id']);
2af58c 101         $username = $this->dataRecord["username"];
MC 102         $old_username = $this->oldDataRecord['username'];
bfcdef 103
T 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']) {
cc7a82 106             $sql = "UPDATE client SET username = ? WHERE client_id = ? AND username = ?";
MC 107             $app->db->query($sql, $username, $client_id, $old_username);
108             $tmp = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE client_id = ?", $client_id);
3a11d2 109             $app->db->datalogUpdate("sys_group", array("name" => $username), 'groupid', $tmp['groupid']);
bfcdef 110             unset($tmp);
T 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"] != '') {
2af58c 115             $password = $this->dataRecord["passwort"];
bfcdef 116             $salt="$1$";
T 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);
cc7a82 123             $sql = "UPDATE client SET password = ? WHERE client_id = ? AND username = ?";
MC 124             $app->db->query($sql, $password, $client_id, $username);
bfcdef 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']) {
2af58c 129             $language = $this->dataRecord["language"];
cc7a82 130             $sql = "UPDATE client SET language = ? WHERE client_id = ? AND username = ?";
MC 131             $app->db->query($sql, $language, $client_id, $username);
bfcdef 132         }
7fe908 133
bfcdef 134         parent::onAfterUpdate();
b998c5 135     }
c4ff82 136
T 137 }
138
139 $page = new page_action;
140 $page->onLoad();
b5a2f8 141
7fe908 142 ?>