@@ -153,39 +153,25 @@ function onShowEnd() {
153153 * If the names are restricted -> remove the restriction, so that the
154154 * data can be edited
155155 */
156- if ($ interfaceConf ['restrict_names ' ] == true ){
157- /* get the restriction */
158- $ restriction = '[CLIENTNAME]_ ' ;
159- if (isset ($ interfaceConf ['restrict_dbname ' ])) $ restriction = $ interfaceConf ['restrict_dbname ' ];
160- $ tmpRestriction = $ restriction ;
161- /* Get the group-id */
162- if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
163- // Get the group-id of the user
164- $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
165- }
166- else {
167- // Get the group-id from the data itself
168- $ client_group_id = $ this ->dataRecord ['sys_groupid ' ];
169- }
170- /* get the name of the client */
171- $ tmp = $ app ->db ->queryOneRecord ("SELECT name FROM sys_group WHERE groupid = " . $ client_group_id );
172- $ clientName = $ tmp ['name ' ];
173- if ($ clientName == "" ) $ clientName = 'default ' ;
174- $ clientName = convertClientName ($ clientName );
175- $ restriction = str_replace ('[CLIENTNAME] ' , $ clientName , $ restriction );
176- if ($ this ->dataRecord ['database_name ' ] != "" ){
177- /* REMOVE the restriction */
178- $ app ->tpl ->setVar ("database_name " , str_replace ($ restriction , '' , $ this ->dataRecord ['database_name ' ]));
179- $ app ->tpl ->setVar ("database_user " , str_replace ($ restriction , '' , $ this ->dataRecord ['database_user ' ]));
180- }
181- if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' || $ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
182- $ app ->tpl ->setVar ("database_name_prefix " , $ tmpRestriction );
183- $ app ->tpl ->setVar ("database_user_prefix " , $ tmpRestriction );
184- }
185- else {
186- $ app ->tpl ->setVar ("database_name_prefix " , $ restriction );
187- $ app ->tpl ->setVar ("database_user_prefix " , $ restriction );
188- }
156+
157+ //* Get the database name and database user prefix
158+ $ app ->uses ('getconf ' );
159+ $ global_config = $ app ->getconf ->get_global_config ('sites ' );
160+ $ dbname_prefix = ($ global_config ['dbname_prefix ' ] == '' )?'' :str_replace ('[CLIENTNAME] ' , $ this ->getClientName (), $ global_config ['dbname_prefix ' ]);
161+ $ dbuser_prefix = ($ global_config ['dbuser_prefix ' ] == '' )?'' :str_replace ('[CLIENTNAME] ' , $ this ->getClientName (), $ global_config ['dbuser_prefix ' ]);
162+
163+ if ($ this ->dataRecord ['database_name ' ] != "" ){
164+ /* REMOVE the restriction */
165+ $ app ->tpl ->setVar ("database_name " , str_replace ($ dbname_prefix , '' , $ this ->dataRecord ['database_name ' ]));
166+ $ app ->tpl ->setVar ("database_user " , str_replace ($ dbuser_prefix , '' , $ this ->dataRecord ['database_user ' ]));
167+ }
168+
169+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' || $ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
170+ $ app ->tpl ->setVar ("database_name_prefix " , $ global_config ['dbname_prefix ' ]);
171+ $ app ->tpl ->setVar ("database_user_prefix " , $ global_config ['dbuser_prefix ' ]);
172+ } else {
173+ $ app ->tpl ->setVar ("database_name_prefix " , $ dbname_prefix );
174+ $ app ->tpl ->setVar ("database_user_prefix " , $ dbuser_prefix );
189175 }
190176
191177 parent ::onShowEnd ();
@@ -233,44 +219,23 @@ function onBeforeUpdate() {
233219 global $ app , $ conf , $ interfaceConf ;
234220
235221 /*
236- * If the names should be restricted -> do it!
237- */
238- if ($ interfaceConf ['restrict_names ' ] == true ){
239- /* get the restriction */
240- $ restriction = '[CLIENTNAME]_ ' ;
241- if (isset ($ interfaceConf ['restrict_dbname ' ])) $ restriction = $ interfaceConf ['restrict_dbname ' ];
242-
243- /* Get the group-id */
244- if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
245- // Get the group-id of the user
246- $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
247- }
248- else {
249- // Get the group-id from the data itself
250- $ client_group_id = $ this ->dataRecord ['client_group_id ' ];
251- }
252- /* get the name of the client */
253- $ tmp = $ app ->db ->queryOneRecord ("SELECT name FROM sys_group WHERE groupid = " . $ client_group_id );
254- $ clientName = $ tmp ['name ' ];
255- if ($ clientName == "" ) $ clientName = 'default ' ;
256- $ clientName = convertClientName ($ clientName );
257- $ restriction = str_replace ('[CLIENTNAME] ' , $ clientName , $ restriction );
258- }
259- else {
260- $ restriction = '' ;
261- }
262-
263- $ error = false ;
222+ * If the names should be restricted -> do it!
223+ */
224+
225+
226+ //* Get the database name and database user prefix
227+ $ app ->uses ('getconf ' );
228+ $ global_config = $ app ->getconf ->get_global_config ('sites ' );
229+ $ dbname_prefix = ($ global_config ['dbname_prefix ' ] == '' )?'' :str_replace ('[CLIENTNAME] ' , $ this ->getClientName (), $ global_config ['dbname_prefix ' ]);
230+ $ dbuser_prefix = ($ global_config ['dbuser_prefix ' ] == '' )?'' :str_replace ('[CLIENTNAME] ' , $ this ->getClientName (), $ global_config ['dbuser_prefix ' ]);
264231
265232 //* Prevent that the database name and charset is changed
266233 $ old_record = $ app ->tform ->getDataRecord ($ this ->id );
267234 if ($ old_record ["database_name " ] != $ restriction . $ this ->dataRecord ["database_name " ]) {
268235 $ app ->tform ->errorMessage .= $ app ->tform ->wordbook ["database_name_change_txt " ].'<br /> ' ;
269- $ error = true ;
270236 }
271237 if ($ old_record ["database_charset " ] != $ this ->dataRecord ["database_charset " ]) {
272238 $ app ->tform ->errorMessage .= $ app ->tform ->wordbook ["database_charset_change_txt " ].'<br /> ' ;
273- $ error = true ;
274239 }
275240
276241 //* Check if the server has been changed
@@ -280,15 +245,14 @@ function onBeforeUpdate() {
280245 //* Add a error message and switch back to old server
281246 $ app ->tform ->errorMessage .= $ app ->lng ('The Server can not be changed. ' );
282247 $ this ->dataRecord ["server_id " ] = $ rec ['server_id ' ];
283- $ error = true ;
284248 }
285249 }
286250 unset($ old_record );
287251
288- if ($ error == false ){
252+ if ($ app -> tform -> errorMessage == '' ){
289253 /* restrict the names if there is no error */
290- $ this ->dataRecord ['database_name ' ] = $ restriction . $ this ->dataRecord ['database_name ' ];
291- $ this ->dataRecord ['database_user ' ] = $ restriction . $ this ->dataRecord ['database_user ' ];
254+ $ this ->dataRecord ['database_name ' ] = $ dbname_prefix . $ this ->dataRecord ['database_name ' ];
255+ $ this ->dataRecord ['database_user ' ] = $ dbuser_prefix . $ this ->dataRecord ['database_user ' ];
292256 }
293257
294258 parent ::onBeforeUpdate ();
@@ -297,34 +261,16 @@ function onBeforeUpdate() {
297261 function onBeforeInsert () {
298262 global $ app , $ conf , $ interfaceConf ;
299263
300- /*
301- * If the names should be restricted -> do it!
302- */
303- if ($ interfaceConf ['restrict_names ' ] == true ){
304- /* get the restriction */
305- $ restriction = '[CLIENTNAME]_ ' ;
306- if (isset ($ interfaceConf ['restrict_dbname ' ])) $ restriction = $ interfaceConf ['restrict_dbname ' ];
307-
308- /* Get the group-id */
309- if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
310- // Get the group-id of the user
311- $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
312- }
313- else {
314- // Get the group-id from the data itself
315- $ client_group_id = $ this ->dataRecord ['client_group_id ' ];
316- }
317- /* get the name of the client */
318- $ tmp = $ app ->db ->queryOneRecord ("SELECT name FROM sys_group WHERE groupid = " . $ client_group_id );
319- $ clientName = $ tmp ['name ' ];
320- if ($ clientName == "" ) $ clientName = 'default ' ;
321- $ clientName = convertClientName ($ clientName );
322- $ restriction = str_replace ('[CLIENTNAME] ' , $ clientName , $ restriction );
323-
324- /* restrict the names */
325- $ this ->dataRecord ['database_name ' ] = $ restriction . $ this ->dataRecord ['database_name ' ];
326- $ this ->dataRecord ['database_user ' ] = $ restriction . $ this ->dataRecord ['database_user ' ];
327- }
264+ //* Get the database name and database user prefix
265+ $ app ->uses ('getconf ' );
266+ $ global_config = $ app ->getconf ->get_global_config ('sites ' );
267+ $ dbname_prefix = ($ global_config ['dbname_prefix ' ] == '' )?'' :str_replace ('[CLIENTNAME] ' , $ this ->getClientName (), $ global_config ['dbname_prefix ' ]);
268+ $ dbuser_prefix = ($ global_config ['dbuser_prefix ' ] == '' )?'' :str_replace ('[CLIENTNAME] ' , $ this ->getClientName (), $ global_config ['dbuser_prefix ' ]);
269+
270+ /* restrict the names */
271+ $ this ->dataRecord ['database_name ' ] = $ dbname_prefix . $ this ->dataRecord ['database_name ' ];
272+ $ this ->dataRecord ['database_user ' ] = $ dbuser_prefix . $ this ->dataRecord ['database_user ' ];
273+
328274 parent ::onBeforeInsert ();
329275 }
330276
@@ -358,6 +304,24 @@ function onAfterUpdate() {
358304 }
359305
360306 }
307+
308+ function getClientName () {
309+ global $ app , $ conf ;
310+
311+ if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
312+ // Get the group-id of the user
313+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
314+ } else {
315+ // Get the group-id from the data itself
316+ $ client_group_id = $ this ->dataRecord ['client_group_id ' ];
317+ }
318+ /* get the name of the client */
319+ $ tmp = $ app ->db ->queryOneRecord ("SELECT name FROM sys_group WHERE groupid = " . $ client_group_id );
320+ $ clientName = $ tmp ['name ' ];
321+ if ($ clientName == "" ) $ clientName = 'default ' ;
322+ $ clientName = convertClientName ($ clientName );
323+
324+ }
361325
362326}
363327
0 commit comments