@@ -336,69 +336,84 @@ function getDatasourceData($field, $record) {
336336 }
337337
338338 //* If the parameter 'valuelimit' is set
339- function applyValueLimit ($ limit , $ values ) {
339+ function applyValueLimit ($ limit , $ values, $ current_value = '' ) {
340340
341341 global $ app ;
342+
343+ // we mas have multiple limits, therefore we explode by ; first
344+ // Example: "system:sites:web_php_options;client:web_php_options"
345+ $ limits = explode ('; ' ,$ limit );
346+
347+
348+ foreach ($ limits as $ limit ) {
342349
343- $ limit_parts = explode (': ' , $ limit );
350+ $ limit_parts = explode (': ' , $ limit );
344351
345- //* values are limited to a comma separated list
346- if ($ limit_parts [0 ] == 'list ' ) {
347- $ allowed = explode (', ' , $ limit_parts [1 ]);
348- }
349-
350- //* values are limited to a field in the client settings
351- if ($ limit_parts [0 ] == 'client ' ) {
352- if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) {
353- return $ values ;
354- } else {
355- $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
356- $ client = $ app ->db ->queryOneRecord ("SELECT " .$ limit_parts [1 ]." as lm FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ client_group_id );
357- $ allowed = explode (', ' , $ client ['lm ' ]);
352+ //* values are limited to a comma separated list
353+ if ($ limit_parts [0 ] == 'list ' ) {
354+ $ allowed = explode (', ' , $ limit_parts [1 ]);
358355 }
359- }
360356
361- //* values are limited to a field in the reseller settings
362- if ($ limit_parts [0 ] == 'reseller ' ) {
363- if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) {
364- return $ values ;
365- } else {
366- //* Get the limits of the client that is currently logged in
367- $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
368- $ client = $ app ->db ->queryOneRecord ("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ client_group_id );
369- //echo "SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id";
370- //* If the client belongs to a reseller, we will check against the reseller Limit too
371- if ($ client ['parent_client_id ' ] != 0 ) {
372-
373- //* first we need to know the groups of this reseller
374- $ tmp = $ app ->db ->queryOneRecord ("SELECT userid, groups FROM sys_user WHERE client_id = ? " , $ client ['parent_client_id ' ]);
375- $ reseller_groups = $ tmp ["groups " ];
376- $ reseller_userid = $ tmp ["userid " ];
377-
378- // Get the limits of the reseller of the logged in client
379- $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
380- $ reseller = $ app ->db ->queryOneRecord ("SELECT " .$ limit_parts [1 ]." as lm FROM client WHERE client_id = ? " , $ client ['parent_client_id ' ]);
381- $ allowed = explode (', ' , $ reseller ['lm ' ]);
382- } else {
357+ //* values are limited to a field in the client settings
358+ if ($ limit_parts [0 ] == 'client ' ) {
359+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) {
383360 return $ values ;
361+ } else {
362+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
363+ $ client = $ app ->db ->queryOneRecord ("SELECT " .$ limit_parts [1 ]." as lm FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ client_group_id );
364+ $ allowed = explode (', ' , $ client ['lm ' ]);
384365 }
385- } // end if admin
386- } // end if reseller
387-
388- //* values are limited to a field in the system settings
389- if ($ limit_parts [0 ] == 'system ' ) {
390- $ app ->uses ('getconf ' );
391- $ tmp_conf = $ app ->getconf ->get_global_config ($ limit_parts [1 ]);
392- $ tmp_key = $ limit_parts [2 ];
393- $ allowed = $ tmp_conf [$ tmp_key ];
394- }
366+ }
367+
368+ //* values are limited to a field in the reseller settings
369+ if ($ limit_parts [0 ] == 'reseller ' ) {
370+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) {
371+ return $ values ;
372+ } else {
373+ //* Get the limits of the client that is currently logged in
374+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
375+ $ client = $ app ->db ->queryOneRecord ("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ client_group_id );
376+ //echo "SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id";
377+ //* If the client belongs to a reseller, we will check against the reseller Limit too
378+ if ($ client ['parent_client_id ' ] != 0 ) {
379+
380+ //* first we need to know the groups of this reseller
381+ $ tmp = $ app ->db ->queryOneRecord ("SELECT userid, groups FROM sys_user WHERE client_id = ? " , $ client ['parent_client_id ' ]);
382+ $ reseller_groups = $ tmp ["groups " ];
383+ $ reseller_userid = $ tmp ["userid " ];
384+
385+ // Get the limits of the reseller of the logged in client
386+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
387+ $ reseller = $ app ->db ->queryOneRecord ("SELECT " .$ limit_parts [1 ]." as lm FROM client WHERE client_id = ? " , $ client ['parent_client_id ' ]);
388+ $ allowed = explode (', ' , $ reseller ['lm ' ]);
389+ } else {
390+ return $ values ;
391+ }
392+ } // end if admin
393+ } // end if reseller
394+
395+ //* values are limited to a field in the system settings
396+ if ($ limit_parts [0 ] == 'system ' ) {
397+ $ app ->uses ('getconf ' );
398+ $ tmp_conf = $ app ->getconf ->get_global_config ($ limit_parts [1 ]);
399+ $ tmp_key = $ limit_parts [2 ];
400+ $ allowed = $ allowed = explode (', ' ,$ tmp_conf [$ tmp_key ]);
401+ }
402+
403+ // add the current value to the allowed array
404+ $ allowed [] = $ current_value ;
405+
406+ // remove all values that are not allowed
407+ $ values_new = array ();
408+ foreach ($ values as $ key => $ val ) {
409+ if (in_array ($ key , $ allowed )) $ values_new [$ key ] = $ val ;
410+ }
411+
412+ $ values = $ values_new ;
395413
396- $ values_new = array ();
397- foreach ($ values as $ key => $ val ) {
398- if (in_array ($ key , $ allowed )) $ values_new [$ key ] = $ val ;
399414 }
400415
401- return $ values_new ;
416+ return $ values ;
402417 }
403418
404419
@@ -464,7 +479,7 @@ function getHTML($record, $tab, $action = 'NEW') {
464479
465480 // If a limitation for the values is set
466481 if (isset ($ field ['valuelimit ' ]) && is_array ($ field ["value " ])) {
467- $ field ["value " ] = $ this ->applyValueLimit ($ field ['valuelimit ' ], $ field ["value " ]);
482+ $ field ["value " ] = $ this ->applyValueLimit ($ field ['valuelimit ' ], $ field ["value " ], $ val );
468483 }
469484
470485 switch ($ field ['formtype ' ]) {
@@ -599,7 +614,7 @@ function getHTML($record, $tab, $action = 'NEW') {
599614
600615 // If a limitation for the values is set
601616 if (isset ($ field ['valuelimit ' ]) && is_array ($ field ["value " ])) {
602- $ field ["value " ] = $ this ->applyValueLimit ($ field ['valuelimit ' ], $ field ["value " ]);
617+ $ field ["value " ] = $ this ->applyValueLimit ($ field ['valuelimit ' ], $ field ["value " ], $ field [ ' default ' ] );
603618 }
604619
605620 switch ($ field ['formtype ' ]) {
0 commit comments