redray
2008-10-25 56dfe60128f99d4199154f7df443723b07c13480
commit | author | age
acbf53 1 <?php
T 2 /*
3 Copyright (c) 2005, Till Brehm, projektfarm Gmbh
4 All rights reserved.
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 */
29
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/client.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
41 require_once('../../lib/config.inc.php');
42 require_once('../../lib/app.inc.php');
43
910093 44 //* Check permissions for module
T 45 $app->auth->check_module_permissions('client');
acbf53 46
T 47 // Loading classes
48 $app->uses('tpl,tform,tform_actions');
76a100 49 $app->load('tform_actions');
acbf53 50
76a100 51 class page_action extends tform_actions {
T 52     
53     /*
54      This function is called automatically right after
55      the data was successful inserted in the database.
56     */
57     function onAfterInsert() {
58         global $app;
59         // Create the group for the client
8500be 60         $sql = "INSERT INTO sys_group (name,description,client_id) VALUES ('".mysql_real_escape_string($this->dataRecord["username"])."','',".$this->id.")";
76a100 61         $app->db->query($sql);
T 62         $groupid = $app->db->insertID();
b5a23a 63         $groups = $groupid;
76a100 64         
8500be 65         $username = mysql_real_escape_string($this->dataRecord["username"]);
T 66         $password = mysql_real_escape_string($this->dataRecord["password"]);
b5a23a 67         $modules = ISPC_INTERFACE_MODULES_ENABLED;
T 68         if($this->dataRecord["limit_client"] > 0) $modules .= ',client';
76a100 69         $startmodule = 'mail';
8500be 70         $usertheme = mysql_real_escape_string($this->dataRecord["usertheme"]);
76a100 71         $type = 'user';
T 72         $active = 1;
8500be 73         $language = mysql_real_escape_string($this->dataRecord["language"]);
76a100 74         
T 75         // Create the controlpaneluser for the client
76         $sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)
b5a23a 77         VALUES ('$username',md5('$password'),'$modules','$startmodule','$usertheme','$type','$active','$language',$groups,$groupid,".$this->id.")";
76a100 78         $app->db->query($sql);
b5a23a 79         
T 80         //* If the user who inserted the client is a reseller (not admin), we will have to add this new client group 
81         //* to his groups, so he can administrate the records of this client.
82         if($_SESSION['s']['user']['typ'] == 'user') {
83             $app->auth->add_group_to_user($_SESSION['s']['user']['userid'],$groupid);
84             $app->db->query("UPDATE client SET parent_client_id = ".intval($_SESSION['s']['user']['client_id'])." WHERE client_id = ".$this->id);
85         }
86         
87         
76a100 88     }
T 89     
90     
91     /*
92      This function is called automatically right after
93      the data was successful updated in the database.
94     */
95     function onAfterUpdate() {
96         global $app;
97         
98         // username changed
99         if(isset($app->tform->diffrec['username'])) {
8500be 100             $username = mysql_real_escape_string($this->dataRecord["username"]);
76a100 101             $client_id = $this->id;
T 102             $sql = "UPDATE sys_user SET username = '$username' WHERE client_id = $client_id";
103             $app->db->query($sql);
104             $sql = "UPDATE sys_group SET name = '$username' WHERE client_id = $client_id";
105             $app->db->query($sql);
106         }
107         
108         // password changed
af8f1b 109         if(isset($this->dataRecord["password"]) && $this->dataRecord["password"] != '') {
8500be 110             $password = mysql_real_escape_string($this->dataRecord["password"]);
22e7f9 111             $client_id = $this->id;
76a100 112             $sql = "UPDATE sys_user SET passwort = md5('$password') WHERE client_id = $client_id";
22e7f9 113             $app->db->query($sql);
76a100 114         }
T 115         
b5a23a 116         // reseller status changed
T 117         if(isset($this->dataRecord["limit_client"])) {
118             $modules = ISPC_INTERFACE_MODULES_ENABLED;
119             if($this->dataRecord["limit_client"] > 0) $modules .= ',client';
8500be 120             $modules = mysql_real_escape_string($modules);
b5a23a 121             $client_id = $this->id;
T 122             $sql = "UPDATE sys_user SET modules = '$modules' WHERE client_id = $client_id";
123             $app->db->query($sql);
124         }
76a100 125     }
T 126     
127     
128 }
129
130 $page = new page_action;
131 $page->onLoad();
acbf53 132
b5a2f8 133 ?>