5252$ lng_file = 'lib/lang/ ' .$ _SESSION ['s ' ]['language ' ].'.lng ' ;
5353include $ lng_file ;
5454
55- if (!$ app ->tform ->checkClientLimit ('limit_domainmodule ' )) {
56- $ app ->uses ('ini_parser,getconf ' );
57- $ settings = $ app ->getconf ->get_global_config ('domains ' );
58- if ($ settings ['use_domain_module ' ] == 'y ' ) {
59- $ app ->error ($ settings ['new_domain_html ' ]);
60- }
61- }
62-
6355
6456class page_action extends tform_actions {
6557
@@ -75,6 +67,16 @@ function onShowNew() {
7567
7668 function onShowEnd () {
7769 global $ app , $ conf , $ wb ;
70+
71+ if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' && $ this ->id == 0 ) {
72+ if (!$ app ->tform ->checkClientLimit ('limit_domainmodule ' )) {
73+ $ app ->uses ('ini_parser,getconf ' );
74+ $ settings = $ app ->getconf ->get_global_config ('domains ' );
75+ if ($ settings ['use_domain_module ' ] == 'y ' ) {
76+ $ app ->error ($ settings ['new_domain_html ' ]);
77+ }
78+ }
79+ }
7880
7981 if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) {
8082 // Getting Clients of the user
@@ -92,6 +94,28 @@ function onShowEnd() {
9294 }
9395 $ app ->tpl ->setVar ("client_group_id " , $ client_select );
9496
97+ } else {
98+ // Get the limits of the client
99+ $ client_group_id = $ app ->functions ->intval ($ _SESSION ["s " ]["user " ]["default_group " ]);
100+ $ client = $ app ->db ->queryOneRecord ("SELECT client.client_id, client.contact_name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname, sys_group.name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $ client_group_id " );
101+
102+ // Fill the client select field
103+ $ sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = " .$ client ['client_id ' ]." ORDER BY sys_group.name " ;
104+ //die($sql);
105+ $ records = $ app ->db ->queryAllRecords ($ sql );
106+ $ tmp = $ app ->db ->queryOneRecord ("SELECT groupid FROM sys_group WHERE client_id = " .$ app ->functions ->intval ($ client ['client_id ' ]));
107+ $ client_select = '<option value=" ' .$ tmp ['groupid ' ].'"> ' .$ client ['contactname ' ].'</option> ' ;
108+ //$tmp_data_record = $app->tform->getDataRecord($this->id);
109+ if (is_array ($ records )) {
110+ $ selected_client_group_id = 0 ; // needed to get list of PHP versions
111+ foreach ( $ records as $ rec ) {
112+ if (is_array ($ this ->dataRecord ) && ($ rec ["groupid " ] == $ this ->dataRecord ['client_group_id ' ] || $ rec ["groupid " ] == $ this ->dataRecord ['sys_groupid ' ]) && !$ selected_client_group_id ) $ selected_client_group_id = $ rec ["groupid " ];
113+ $ selected = @(is_array ($ this ->dataRecord ) && ($ rec ["groupid " ] == $ this ->dataRecord ['client_group_id ' ] || $ rec ["groupid " ] == $ this ->dataRecord ['sys_groupid ' ]))?'SELECTED ' :'' ;
114+ if ($ selected == 'SELECTED ' ) $ selected_client_group_id = $ rec ["groupid " ];
115+ $ client_select .= "<option value=' $ rec [groupid]' $ selected> $ rec [contactname]</option> \r\n" ;
116+ }
117+ }
118+ $ app ->tpl ->setVar ("client_group_id " , $ client_select );
95119 }
96120
97121 if ($ this ->id > 0 ) {
@@ -127,6 +151,24 @@ function onSubmit() {
127151 */
128152 $ this ->dataRecord = $ app ->tform ->getDataRecord ($ this ->id );
129153 }
154+ } elseif ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' && $ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
155+ if ($ this ->id == 0 ) {
156+ /*
157+ * We create a new record
158+ */
159+ // Check if the user is empty
160+ if (isset ($ this ->dataRecord ['client_group_id ' ]) && $ this ->dataRecord ['client_group_id ' ] == 0 ) {
161+ $ app ->tform ->errorMessage .= $ wb ['error_client_group_id_empty ' ];
162+ }
163+ //* make sure that the domain is lowercase
164+ if (isset ($ this ->dataRecord ["domain " ])) $ this ->dataRecord ["domain " ] = strtolower ($ this ->dataRecord ["domain " ]);
165+ }
166+ else {
167+ /*
168+ * We edit a existing one, but there is nothing to edit
169+ */
170+ $ this ->dataRecord = $ app ->tform ->getDataRecord ($ this ->id );
171+ }
130172 } else {
131173 if ($ this ->id > 0 ) {
132174 /*
0 commit comments