@@ -71,12 +71,54 @@ function onShowNew() {
7171 function onShowEnd () {
7272 global $ app , $ conf ;
7373
74- // Get the record of the parent domain
75- $ parent_domain = $ app ->db ->queryOneRecord ("select * FROM web_domain WHERE domain_id = " .intval (@$ this ->dataRecord ["parent_domain_id " ]));
76-
77- // remove the parent domain part of the domain name before we show it in the text field.
78- $ this ->dataRecord ["domain " ] = str_replace ('. ' .$ parent_domain ["domain " ],'' ,$ this ->dataRecord ["domain " ]);
79- $ app ->tpl ->setVar ("domain " ,$ this ->dataRecord ["domain " ]);
74+ $ app ->uses ('ini_parser,getconf ' );
75+ $ settings = $ app ->getconf ->get_global_config ('domains ' );
76+ if ($ settings ['use_domain_module ' ] == 'y ' ) {
77+ /*
78+ * The domain-module is in use.
79+ */
80+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
81+ /*
82+ * The admin can select ALL domains, the user only the domains assigned to him
83+ */
84+ $ sql = "SELECT domain_id, domain FROM domain " ;
85+ if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
86+ $ sql .= "WHERE sys_groupid = " . $ client_group_id ;
87+ }
88+ $ sql .= " ORDER BY domain " ;
89+ $ domains = $ app ->db ->queryAllRecords ($ sql );
90+ $ domain_select = '' ;
91+ $ selected_domain = '' ;
92+ if (is_array ($ domains ) && sizeof ($ domains ) > 0 ) {
93+ /* We have domains in the list, so create the drop-down-list */
94+ foreach ( $ domains as $ domain ) {
95+ $ domain_select .= "<option value= " . $ domain ['domain_id ' ] ;
96+ if ('. ' . $ domain ['domain ' ] == substr ($ this ->dataRecord ["domain " ], -strlen ($ domain ['domain ' ]) - 1 )) {
97+ $ domain_select .= " selected " ;
98+ $ selected_domain = $ domain ['domain ' ];
99+ }
100+ $ domain_select .= "> " . $ domain ['domain ' ] . "</option> \r\n" ;
101+ }
102+ }
103+ else {
104+ /*
105+ * We have no domains in the domain-list. This means, we can not add ANY new domain.
106+ * To avoid, that the variable "domain_option" is empty and so the user can
107+ * free enter a domain, we have to create a empty option!
108+ */
109+ $ domain_select .= "<option value=''></option> \r\n" ;
110+ }
111+ $ app ->tpl ->setVar ("domain_option " ,$ domain_select );
112+ $ this ->dataRecord ['domain ' ] = substr ($ this ->dataRecord ["domain " ], 0 , strlen ($ this ->dataRecord ['domain ' ]) - strlen ($ selected_domain ) - 1 );
113+ } else {
114+
115+ // Get the record of the parent domain
116+ $ parent_domain = $ app ->db ->queryOneRecord ("select * FROM web_domain WHERE domain_id = " .intval (@$ this ->dataRecord ["parent_domain_id " ]));
117+
118+ // remove the parent domain part of the domain name before we show it in the text field.
119+ $ this ->dataRecord ["domain " ] = str_replace ('. ' .$ parent_domain ["domain " ],'' ,$ this ->dataRecord ["domain " ]);
120+ }
121+ $ app ->tpl ->setVar ("domain " ,$ this ->dataRecord ["domain " ]);
80122
81123 parent ::onShowEnd ();
82124
@@ -85,17 +127,30 @@ function onShowEnd() {
85127 function onSubmit () {
86128 global $ app , $ conf ;
87129
88- // Get the record of the parent domain
89- $ parent_domain = $ app ->db ->queryOneRecord ("select * FROM web_domain WHERE domain_id = " .intval (@$ this ->dataRecord ["parent_domain_id " ]));
90-
130+ // Get the record of the parent domain
131+ $ parent_domain = $ app ->db ->queryOneRecord ("SELECT * FROM web_domain WHERE domain_id = " .intval (@$ this ->dataRecord ["parent_domain_id " ]));
132+
133+ $ app ->uses ('ini_parser,getconf ' );
134+ $ settings = $ app ->getconf ->get_global_config ('domains ' );
135+ if ($ settings ['use_domain_module ' ] == 'y ' ) {
136+ // get the record of the domain module domain
137+ $ domain = $ app ->db ->queryOneRecord ("SELECT * FROM domain WHERE domain_id = " .intval ($ this ->dataRecord ["sel_domain " ]));
138+ if (!$ domain ) {
139+ $ app ->tform ->errorMessage .= $ app ->tform ->lng ("domain_error_empty " )."<br /> " ;
140+ } else {
141+ $ this ->dataRecord ['domain ' ] = $ this ->dataRecord ['domain ' ] . '. ' . $ domain ['domain ' ];
142+ }
143+ } else {
144+ $ this ->dataRecord ["domain " ] = $ this ->dataRecord ["domain " ].'. ' .$ parent_domain ["domain " ];
145+ }
146+
91147 // Set a few fixed values
92148 $ this ->dataRecord ["type " ] = 'subdomain ' ;
93149 $ this ->dataRecord ["server_id " ] = $ parent_domain ["server_id " ];
94- $ this ->dataRecord ["domain " ] = $ this ->dataRecord ["domain " ].'. ' .$ parent_domain ["domain " ];
95150
96151 $ this ->parent_domain_record = $ parent_domain ;
97152
98- //* make sure that the email domain is lowercase
153+ //* make sure that the domain is lowercase
99154 if (isset ($ this ->dataRecord ["domain " ])) $ this ->dataRecord ["domain " ] = strtolower ($ this ->dataRecord ["domain " ]);
100155
101156 parent ::onSubmit ();
@@ -108,6 +163,22 @@ function onAfterInsert() {
108163
109164 }
110165
166+ function onAfterUpdate () {
167+ global $ app , $ conf ;
168+
169+ //* Check if parent domain has been changed
170+ if ($ this ->dataRecord ['parent_domain_id ' ] != $ this ->oldDataRecord ['parent_domain_id ' ]) {
171+
172+ //* Update the domain owner
173+ $ app ->db ->query ('UPDATE web_domain SET sys_groupid = ' .intval ($ this ->parent_domain_record ['sys_groupid ' ]).' WHERE domain_id = ' .$ this ->id );
174+
175+ //* Update the old website, so that the vhost alias gets removed
176+ //* We force the update by inserting a transaction record without changes manually.
177+ $ old_website = $ app ->db ->queryOneRecord ('SELECT * FROM web_domain WHERE domain_id = ' .$ this ->oldDataRecord ['domain_id ' ]);
178+ $ app ->db ->datalogSave ('web_domain ' , 'UPDATE ' , 'domain_id ' , $ this ->oldDataRecord ['parent_domain_id ' ], $ old_website , $ old_website , true );
179+ }
180+
181+ }
111182
112183}
113184
0 commit comments