1- <?php
2- /*
3- Copyright (c) 2005 - 2008, 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- require_once ('tools.inc.php ' );
44-
45- //* Check permissions for module
46- $ app ->auth ->check_module_permissions ('client ' );
47-
48- // Loading classes
49- $ app ->uses ('tpl,tform,tform_actions ' );
50- $ app ->load ('tform_actions ' );
51-
52- class page_action extends tform_actions {
53-
54-
55- function onShowEnd () {
56-
57- global $ app ;
58-
59- $ sql = "SELECT template_id,template_name FROM client_template WHERE template_type = 'a' " ;
60- $ tpls = $ app ->db ->queryAllRecords ($ sql );
61- $ option = '' ;
62- $ tpl = array ();
63- foreach ($ tpls as $ item ){
64- $ option .= '<option value=" ' . $ item ['template_id ' ] . '| ' . $ item ['template_name ' ] . '"> ' . $ item ['template_name ' ] . '</option> ' ;
65- $ tpl [$ item ['template_id ' ]] = $ item ['template_name ' ];
66- }
67- $ app ->tpl ->setVar ('tpl_add_select ' ,$ option );
68-
69- $ sql = "SELECT template_additional FROM client WHERE client_id = " . $ this ->id ;
70- $ result = $ app ->db ->queryOneRecord ($ sql );
71- $ tplAdd = explode ("/ " , $ result ['template_additional ' ]);
72- $ text = '' ;
73- foreach ($ tplAdd as $ item ){
74- if (trim ($ item ) != '' ){
75- if ($ text != '' ) $ text .= '<br /> ' ;
76- $ text .= $ tpl [$ item ];
77- }
78- }
79-
80- $ app ->tpl ->setVar ('template_additional_list ' , $ text );
81-
82- parent ::onShowEnd ();
83-
84- }
85-
86- /*
87- This function is called automatically right after
88- the data was successful inserted in the database.
89- */
90- function onAfterInsert () {
91- global $ app ;
92- // Create the group for the client
93- $ groupid = $ app ->db ->datalogInsert ('sys_group ' , "(name,description,client_id) VALUES (' " .mysql_real_escape_string ($ this ->dataRecord ["username " ])."','', " .$ this ->id .") " , 'groupid ' );
94- $ groups = $ groupid ;
95-
96- $ username = $ app ->db ->quote ($ this ->dataRecord ["username " ]);
97- $ password = $ app ->db ->quote ($ this ->dataRecord ["password " ]);
98- $ modules = ISPC_INTERFACE_MODULES_ENABLED ;
99- if ($ this ->dataRecord ["limit_client " ] > 0 ) $ modules .= ',client ' ;
100- $ startmodule = 'mail ' ;
101- $ usertheme = $ app ->db ->quote ($ this ->dataRecord ["usertheme " ]);
102- $ type = 'user ' ;
103- $ active = 1 ;
104- $ language = $ app ->db ->quote ($ this ->dataRecord ["language " ]);
105-
106- // Create the controlpaneluser for the client
107- $ sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)
108- VALUES (' $ username',md5(' $ password'),' $ modules',' $ startmodule',' $ usertheme',' $ type',' $ active',' $ language', $ groups, $ groupid, " .$ this ->id .") " ;
109- $ app ->db ->query ($ sql );
110-
111- //* If the user who inserted the client is a reseller (not admin), we will have to add this new client group
112- //* to his groups, so he can administrate the records of this client.
113- if ($ _SESSION ['s ' ]['user ' ]['typ ' ] == 'user ' ) {
114- $ app ->auth ->add_group_to_user ($ _SESSION ['s ' ]['user ' ]['userid ' ],$ groupid );
115- $ app ->db ->query ("UPDATE client SET parent_client_id = " .intval ($ _SESSION ['s ' ]['user ' ]['client_id ' ])." WHERE client_id = " .$ this ->id );
116- }
117-
118- /* If there is a client-template, process it */
119- applyClientTemplates ($ this ->id );
120-
121- parent ::onAfterInsert ();
122- }
123-
124-
125- /*
126- This function is called automatically right after
127- the data was successful updated in the database.
128- */
129- function onAfterUpdate () {
130- global $ app ;
131-
132- // username changed
133- if (isset ($ this ->dataRecord ['username ' ]) && $ this ->dataRecord ['username ' ] != '' && $ this ->oldDataRecord ['username ' ] != $ this ->dataRecord ['username ' ]) {
134- $ username = $ app ->db ->quote ($ this ->dataRecord ["username " ]);
135- $ client_id = $ this ->id ;
136- $ sql = "UPDATE sys_user SET username = ' $ username' WHERE client_id = $ client_id " ;
137- $ app ->db ->query ($ sql );
138-
139- $ tmp = $ app ->db ->queryOneRecord ("SELECT * FROM sys_group WHERE client_id = $ client_id " );
140- $ app ->db ->datalogUpdate ("sys_group " , "name = ' $ username' " , 'groupid ' , $ tmp ['groupid ' ]);
141- unset($ tmp );
142- }
143-
144- // password changed
145- if (isset ($ this ->dataRecord ["password " ]) && $ this ->dataRecord ["password " ] != '' ) {
146- $ password = $ app ->db ->quote ($ this ->dataRecord ["password " ]);
147- $ client_id = $ this ->id ;
148- $ sql = "UPDATE sys_user SET passwort = md5(' $ password') WHERE client_id = $ client_id " ;
149- $ app ->db ->query ($ sql );
150- }
151-
152- // reseller status changed
153- if (isset ($ this ->dataRecord ["limit_client " ]) && $ this ->dataRecord ["limit_client " ] != $ this ->oldDataRecord ["limit_client " ]) {
154- $ modules = ISPC_INTERFACE_MODULES_ENABLED ;
155- if ($ this ->dataRecord ["limit_client " ] > 0 ) $ modules .= ',client ' ;
156- $ modules = $ app ->db ->quote ($ modules );
157- $ client_id = $ this ->id ;
158- $ sql = "UPDATE sys_user SET modules = ' $ modules' WHERE client_id = $ client_id " ;
159- $ app ->db ->query ($ sql );
160- }
161- /*
162- * If there is a client-template, process it */
163- applyClientTemplates ($ this ->id );
164-
165- parent ::onAfterUpdate ();
166- }
167- }
168-
169- $ page = new page_action ;
170- $ page ->onLoad ();
171-
1+ <?php
2+ /*
3+ Copyright (c) 2005 - 2008, 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+ require_once ('tools.inc.php ' );
44+
45+ //* Check permissions for module
46+ $ app ->auth ->check_module_permissions ('client ' );
47+
48+ // Loading classes
49+ $ app ->uses ('tpl,tform,tform_actions ' );
50+ $ app ->load ('tform_actions ' );
51+
52+ class page_action extends tform_actions {
53+
54+
55+ function onShowNew () {
56+ global $ app , $ conf ;
57+
58+ // we will check only users, not admins
59+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'user ' ) {
60+
61+ // Get the limits of the client
62+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
63+ $ client = $ app ->db ->queryOneRecord ("SELECT limit_client FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $ client_group_id " );
64+
65+ // Check if the user may add another website.
66+ if ($ client ["limit_client " ] >= 0 ) {
67+ $ tmp = $ app ->db ->queryOneRecord ("SELECT count(client_id) as number FROM client WHERE sys_groupid = $ client_group_id " );
68+ if ($ tmp ["number " ] >= $ client ["limit_client " ]) {
69+ $ app ->error ($ app ->tform ->wordbook ["limit_client_txt " ]);
70+ }
71+ }
72+ }
73+
74+ parent ::onShowNew ();
75+ }
76+
77+
78+ function onSubmit () {
79+ global $ app , $ conf ;
80+
81+ // we will check only users, not admins
82+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'user ' && $ this ->id == 0 ) {
83+
84+ // Get the limits of the client
85+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
86+ $ client = $ app ->db ->queryOneRecord ("SELECT limit_client FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $ client_group_id " );
87+
88+ // Check if the user may add another website.
89+ if ($ client ["limit_client " ] >= 0 ) {
90+ $ tmp = $ app ->db ->queryOneRecord ("SELECT count(client_id) as number FROM client WHERE sys_groupid = $ client_group_id " );
91+ if ($ tmp ["number " ] >= $ client ["limit_client " ]) {
92+ $ app ->error ($ app ->tform ->wordbook ["limit_client_txt " ]);
93+ }
94+ }
95+ }
96+
97+ parent ::onSubmit ();
98+ }
99+
100+
101+ function onShowEnd () {
102+
103+ global $ app ;
104+
105+ $ sql = "SELECT template_id,template_name FROM client_template WHERE template_type = 'a' " ;
106+ $ tpls = $ app ->db ->queryAllRecords ($ sql );
107+ $ option = '' ;
108+ $ tpl = array ();
109+ foreach ($ tpls as $ item ){
110+ $ option .= '<option value=" ' . $ item ['template_id ' ] . '| ' . $ item ['template_name ' ] . '"> ' . $ item ['template_name ' ] . '</option> ' ;
111+ $ tpl [$ item ['template_id ' ]] = $ item ['template_name ' ];
112+ }
113+ $ app ->tpl ->setVar ('tpl_add_select ' ,$ option );
114+
115+ $ sql = "SELECT template_additional FROM client WHERE client_id = " . $ this ->id ;
116+ $ result = $ app ->db ->queryOneRecord ($ sql );
117+ $ tplAdd = explode ("/ " , $ result ['template_additional ' ]);
118+ $ text = '' ;
119+ foreach ($ tplAdd as $ item ){
120+ if (trim ($ item ) != '' ){
121+ if ($ text != '' ) $ text .= '<br /> ' ;
122+ $ text .= $ tpl [$ item ];
123+ }
124+ }
125+
126+ $ app ->tpl ->setVar ('template_additional_list ' , $ text );
127+
128+ parent ::onShowEnd ();
129+
130+ }
131+
132+ /*
133+ This function is called automatically right after
134+ the data was successful inserted in the database.
135+ */
136+ function onAfterInsert () {
137+ global $ app ;
138+ // Create the group for the client
139+ $ groupid = $ app ->db ->datalogInsert ('sys_group ' , "(name,description,client_id) VALUES (' " .mysql_real_escape_string ($ this ->dataRecord ["username " ])."','', " .$ this ->id .") " , 'groupid ' );
140+ $ groups = $ groupid ;
141+
142+ $ username = $ app ->db ->quote ($ this ->dataRecord ["username " ]);
143+ $ password = $ app ->db ->quote ($ this ->dataRecord ["password " ]);
144+ $ modules = ISPC_INTERFACE_MODULES_ENABLED ;
145+ if ($ this ->dataRecord ["limit_client " ] > 0 ) $ modules .= ',client ' ;
146+ $ startmodule = 'mail ' ;
147+ $ usertheme = $ app ->db ->quote ($ this ->dataRecord ["usertheme " ]);
148+ $ type = 'user ' ;
149+ $ active = 1 ;
150+ $ language = $ app ->db ->quote ($ this ->dataRecord ["language " ]);
151+
152+ // Create the controlpaneluser for the client
153+ $ sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)
154+ VALUES (' $ username',md5(' $ password'),' $ modules',' $ startmodule',' $ usertheme',' $ type',' $ active',' $ language', $ groups, $ groupid, " .$ this ->id .") " ;
155+ $ app ->db ->query ($ sql );
156+
157+ //* If the user who inserted the client is a reseller (not admin), we will have to add this new client group
158+ //* to his groups, so he can administrate the records of this client.
159+ if ($ _SESSION ['s ' ]['user ' ]['typ ' ] == 'user ' ) {
160+ $ app ->auth ->add_group_to_user ($ _SESSION ['s ' ]['user ' ]['userid ' ],$ groupid );
161+ $ app ->db ->query ("UPDATE client SET parent_client_id = " .intval ($ _SESSION ['s ' ]['user ' ]['client_id ' ])." WHERE client_id = " .$ this ->id );
162+ }
163+
164+ /* If there is a client-template, process it */
165+ applyClientTemplates ($ this ->id );
166+
167+ parent ::onAfterInsert ();
168+ }
169+
170+
171+ /*
172+ This function is called automatically right after
173+ the data was successful updated in the database.
174+ */
175+ function onAfterUpdate () {
176+ global $ app ;
177+
178+ // username changed
179+ if (isset ($ this ->dataRecord ['username ' ]) && $ this ->dataRecord ['username ' ] != '' && $ this ->oldDataRecord ['username ' ] != $ this ->dataRecord ['username ' ]) {
180+ $ username = $ app ->db ->quote ($ this ->dataRecord ["username " ]);
181+ $ client_id = $ this ->id ;
182+ $ sql = "UPDATE sys_user SET username = ' $ username' WHERE client_id = $ client_id " ;
183+ $ app ->db ->query ($ sql );
184+
185+ $ tmp = $ app ->db ->queryOneRecord ("SELECT * FROM sys_group WHERE client_id = $ client_id " );
186+ $ app ->db ->datalogUpdate ("sys_group " , "name = ' $ username' " , 'groupid ' , $ tmp ['groupid ' ]);
187+ unset($ tmp );
188+ }
189+
190+ // password changed
191+ if (isset ($ this ->dataRecord ["password " ]) && $ this ->dataRecord ["password " ] != '' ) {
192+ $ password = $ app ->db ->quote ($ this ->dataRecord ["password " ]);
193+ $ client_id = $ this ->id ;
194+ $ sql = "UPDATE sys_user SET passwort = md5(' $ password') WHERE client_id = $ client_id " ;
195+ $ app ->db ->query ($ sql );
196+ }
197+
198+ // reseller status changed
199+ if (isset ($ this ->dataRecord ["limit_client " ]) && $ this ->dataRecord ["limit_client " ] != $ this ->oldDataRecord ["limit_client " ]) {
200+ $ modules = ISPC_INTERFACE_MODULES_ENABLED ;
201+ if ($ this ->dataRecord ["limit_client " ] > 0 ) $ modules .= ',client ' ;
202+ $ modules = $ app ->db ->quote ($ modules );
203+ $ client_id = $ this ->id ;
204+ $ sql = "UPDATE sys_user SET modules = ' $ modules' WHERE client_id = $ client_id " ;
205+ $ app ->db ->query ($ sql );
206+ }
207+ /*
208+ * If there is a client-template, process it */
209+ applyClientTemplates ($ this ->id );
210+
211+ parent ::onAfterUpdate ();
212+ }
213+ }
214+
215+ $ page = new page_action ;
216+ $ page ->onLoad ();
217+
172218?>
0 commit comments