@@ -82,22 +82,30 @@ function onShowNew() {
8282 function onShowEnd () {
8383 global $ app , $ conf ;
8484
85- // If user is admin, we will allow him to select to whom this record belongs
86- if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) {
87- // Getting Domains of the user
88- $ 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 sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name " ;
89- $ clients = $ app ->db ->queryAllRecords ($ sql );
90- $ client_select = '' ;
91- if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) $ client_select .= "<option value='0'></option> " ;
92- //$tmp_data_record = $app->tform->getDataRecord($this->id);
93- if (is_array ($ clients )) {
94- foreach ( $ clients as $ client ) {
95- $ selected = @(is_array ($ this ->dataRecord ) && ($ client ["groupid " ] == $ this ->dataRecord ['client_group_id ' ] || $ client ["groupid " ] == $ this ->dataRecord ['sys_groupid ' ]))?'SELECTED ' :'' ;
96- $ client_select .= "<option value=' $ client [groupid]' $ selected> $ client [contactname]</option> \r\n" ;
85+ $ app ->uses ('ini_parser,getconf ' );
86+ $ settings = $ app ->getconf ->get_global_config ('domains ' );
87+
88+ /*
89+ * Now we have to check, if we should use the domain-module to select the domain
90+ * or not
91+ */
92+ if ($ settings ['use_domain_module ' ] != 'y ' ) {
93+ // If user is admin, we will allow him to select to whom this record belongs
94+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) {
95+ // Getting Domains of the user
96+ $ 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 sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name " ;
97+ $ clients = $ app ->db ->queryAllRecords ($ sql );
98+ $ client_select = '' ;
99+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' ) $ client_select .= "<option value='0'></option> " ;
100+ //$tmp_data_record = $app->tform->getDataRecord($this->id);
101+ if (is_array ($ clients )) {
102+ foreach ( $ clients as $ client ) {
103+ $ selected = @(is_array ($ this ->dataRecord ) && ($ client ["groupid " ] == $ this ->dataRecord ['client_group_id ' ] || $ client ["groupid " ] == $ this ->dataRecord ['sys_groupid ' ]))?'SELECTED ' :'' ;
104+ $ client_select .= "<option value=' $ client [groupid]' $ selected> $ client [contactname]</option> \r\n" ;
105+ }
97106 }
98- }
99- $ app ->tpl ->setVar ("client_group_id " , $ client_select );
100- } else if ($ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
107+ $ app ->tpl ->setVar ("client_group_id " , $ client_select );
108+ } else if ($ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
101109
102110 // Get the limits of the client
103111 $ client_group_id = intval ($ _SESSION ["s " ]["user " ]["default_group " ]);
@@ -118,7 +126,7 @@ function onShowEnd() {
118126 $ app ->tpl ->setVar ("client_group_id " , $ client_select );
119127
120128 }
121- $ app -> tpl -> setVar ( " client_group_id " , $ client_select );
129+ }
122130
123131// }
124132
@@ -150,12 +158,6 @@ function onShowEnd() {
150158
151159 }
152160
153- /*
154- * Now we have to check, if we should use the domain-module to select the domain
155- * or not
156- */
157- $ app ->uses ('ini_parser,getconf ' );
158- $ settings = $ app ->getconf ->get_global_config ('domains ' );
159161 if ($ settings ['use_domain_module ' ] == 'y ' ) {
160162 /*
161163 * The domain-module is in use.
@@ -197,75 +199,79 @@ function onShowEnd() {
197199function onSubmit () {
198200 global $ app , $ conf ;
199201
200- /* check if the domain module is used - and check if the selected domain can be used! */
201- $ app ->uses ('ini_parser,getconf ' );
202- $ settings = $ app ->getconf ->get_global_config ('domains ' );
203- if ($ settings ['use_domain_module ' ] == 'y ' ) {
204- $ domain_check = $ app ->tools_sites ->checkDomainModuleDomain ($ this ->dataRecord ['origin ' ]);
205- if (!$ domain_check ) {
206- // invalid domain selected
207- $ app ->tform ->errorMessage .= $ app ->tform ->lng ("origin_error_empty " )."<br /> " ;
208- } else {
209- $ this ->dataRecord ['origin ' ] = $ domain_check .'. ' ;
202+ if ($ app ->tform ->getCurrentTab () == 'dns_soa ' ) {
203+ /* check if the domain module is used - and check if the selected domain can be used! */
204+ $ app ->uses ('ini_parser,getconf ' );
205+ $ settings = $ app ->getconf ->get_global_config ('domains ' );
206+ if ($ settings ['use_domain_module ' ] == 'y ' ) {
207+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' || $ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
208+ $ this ->dataRecord ['client_group_id ' ] = $ app ->tools_sites ->getClientIdForDomain ($ this ->dataRecord ['origin ' ]);
209+ }
210+ $ domain_check = $ app ->tools_sites ->checkDomainModuleDomain ($ this ->dataRecord ['origin ' ]);
211+ if (!$ domain_check ) {
212+ // invalid domain selected
213+ $ app ->tform ->errorMessage .= $ app ->tform ->lng ("origin_error_empty " )."<br /> " ;
214+ } else {
215+ $ this ->dataRecord ['origin ' ] = $ domain_check .'. ' ;
216+ }
210217 }
211- }
212218
213- if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
214- // Get the limits of the client
215- $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
216- $ client = $ app ->db ->queryOneRecord ("SELECT limit_dns_zone, dns_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $ client_group_id " );
219+ if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
220+ // Get the limits of the client
221+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
222+ $ client = $ app ->db ->queryOneRecord ("SELECT limit_dns_zone, dns_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $ client_group_id " );
217223
218- $ client ['dns_servers_ids ' ] = explode (', ' , $ client ['dns_servers ' ]);
224+ $ client ['dns_servers_ids ' ] = explode (', ' , $ client ['dns_servers ' ]);
219225
220- // Check if chosen server is in authorized servers for this client
221- if (!(is_array ($ client ['dns_servers_ids ' ]) && in_array ($ this ->dataRecord ["server_id " ], $ client ['dns_servers_ids ' ])) && $ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
222- $ app ->error ($ app ->tform ->wordbook ['error_not_allowed_server_id ' ]);
223- }
226+ // Check if chosen server is in authorized servers for this client
227+ if (!(is_array ($ client ['dns_servers_ids ' ]) && in_array ($ this ->dataRecord ["server_id " ], $ client ['dns_servers_ids ' ])) && $ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
228+ $ app ->error ($ app ->tform ->wordbook ['error_not_allowed_server_id ' ]);
229+ }
224230
225- // When the record is updated
226- if ($ this ->id > 0 ) {
227- // restore the server ID if the user is not admin and record is edited
228- $ tmp = $ app ->db ->queryOneRecord ("SELECT server_id FROM dns_soa WHERE id = " .$ app ->functions ->intval ($ this ->id ));
229- $ this ->dataRecord ["server_id " ] = $ tmp ["server_id " ];
230- unset($ tmp );
231- // When the record is inserted
232- } else {
233- // Check if the user may add another maildomain.
234- if ($ client ["limit_dns_zone " ] >= 0 ) {
235- $ tmp = $ app ->db ->queryOneRecord ("SELECT count(id) as number FROM dns_soa WHERE sys_groupid = $ client_group_id " );
236- if ($ tmp ["number " ] >= $ client ["limit_dns_zone " ]) {
237- $ app ->error ($ app ->tform ->wordbook ["limit_dns_zone_txt " ]);
231+ // When the record is updated
232+ if ($ this ->id > 0 ) {
233+ // restore the server ID if the user is not admin and record is edited
234+ $ tmp = $ app ->db ->queryOneRecord ("SELECT server_id FROM dns_soa WHERE id = " .$ app ->functions ->intval ($ this ->id ));
235+ $ this ->dataRecord ["server_id " ] = $ tmp ["server_id " ];
236+ unset($ tmp );
237+ // When the record is inserted
238+ } else {
239+ // Check if the user may add another maildomain.
240+ if ($ client ["limit_dns_zone " ] >= 0 ) {
241+ $ tmp = $ app ->db ->queryOneRecord ("SELECT count(id) as number FROM dns_soa WHERE sys_groupid = $ client_group_id " );
242+ if ($ tmp ["number " ] >= $ client ["limit_dns_zone " ]) {
243+ $ app ->error ($ app ->tform ->wordbook ["limit_dns_zone_txt " ]);
244+ }
238245 }
239246 }
240247 }
241- }
242248
243- /*
244- // Update the serial number of the SOA record
245- $soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$this->id);
246- $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
247- */
249+ /*
250+ // Update the serial number of the SOA record
251+ $soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$this->id);
252+ $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
253+ */
248254
249255
250- //* Check if soa, ns and mbox have a dot at the end
251- if (strlen ($ this ->dataRecord ["origin " ]) > 0 && substr ($ this ->dataRecord ["origin " ], -1 , 1 ) != '. ' ) $ this ->dataRecord ["origin " ] .= '. ' ;
252- if (strlen ($ this ->dataRecord ["ns " ]) > 0 && substr ($ this ->dataRecord ["ns " ], -1 , 1 ) != '. ' ) $ this ->dataRecord ["ns " ] .= '. ' ;
253- if (strlen ($ this ->dataRecord ["mbox " ]) > 0 && substr ($ this ->dataRecord ["mbox " ], -1 , 1 ) != '. ' ) $ this ->dataRecord ["mbox " ] .= '. ' ;
256+ //* Check if soa, ns and mbox have a dot at the end
257+ if (strlen ($ this ->dataRecord ["origin " ]) > 0 && substr ($ this ->dataRecord ["origin " ], -1 , 1 ) != '. ' ) $ this ->dataRecord ["origin " ] .= '. ' ;
258+ if (strlen ($ this ->dataRecord ["ns " ]) > 0 && substr ($ this ->dataRecord ["ns " ], -1 , 1 ) != '. ' ) $ this ->dataRecord ["ns " ] .= '. ' ;
259+ if (strlen ($ this ->dataRecord ["mbox " ]) > 0 && substr ($ this ->dataRecord ["mbox " ], -1 , 1 ) != '. ' ) $ this ->dataRecord ["mbox " ] .= '. ' ;
254260
255- //* Replace @ in mbox
256- if (stristr ($ this ->dataRecord ["mbox " ], '@ ' )) {
257- $ this ->dataRecord ["mbox " ] = str_replace ('@ ' , '. ' , $ this ->dataRecord ["mbox " ]);
258- }
261+ //* Replace @ in mbox
262+ if (stristr ($ this ->dataRecord ["mbox " ], '@ ' )) {
263+ $ this ->dataRecord ["mbox " ] = str_replace ('@ ' , '. ' , $ this ->dataRecord ["mbox " ]);
264+ }
259265
260- $ this ->dataRecord ["xfer " ] = preg_replace ('/\s+/ ' , '' , $ this ->dataRecord ["xfer " ]);
261- $ this ->dataRecord ["also_notify " ] = preg_replace ('/\s+/ ' , '' , $ this ->dataRecord ["also_notify " ]);
266+ $ this ->dataRecord ["xfer " ] = preg_replace ('/\s+/ ' , '' , $ this ->dataRecord ["xfer " ]);
267+ $ this ->dataRecord ["also_notify " ] = preg_replace ('/\s+/ ' , '' , $ this ->dataRecord ["also_notify " ]);
262268
263- //* Check if a secondary zone with the same name already exists
264- $ tmp = $ app ->db ->queryOneRecord ("SELECT count(id) as number FROM dns_slave WHERE origin = ? AND server_id = ? " , $ this ->dataRecord ["origin " ], $ this ->dataRecord ["server_id " ]);
265- if ($ tmp ["number " ] > 0 ) {
266- $ app ->error ($ app ->tform ->wordbook ["origin_error_unique " ]);
269+ //* Check if a secondary zone with the same name already exists
270+ $ tmp = $ app ->db ->queryOneRecord ("SELECT count(id) as number FROM dns_slave WHERE origin = ? AND server_id = ? " , $ this ->dataRecord ["origin " ], $ this ->dataRecord ["server_id " ]);
271+ if ($ tmp ["number " ] > 0 ) {
272+ $ app ->error ($ app ->tform ->wordbook ["origin_error_unique " ]);
273+ }
267274 }
268-
269275 parent ::onSubmit ();
270276}
271277
0 commit comments