1717 param name = " form.billing_address" default = " " ;
1818 param name = " form.billing_info" default = " " ;
1919
20- // Check whether the email is valid
20+ // Check whether the email is valid
2121 checkEmail = application .objGlobal .checkEmail (form .email );
2222 if (! checkEmail ) {
2323 getAlert (' alertEnterEmail' , ' warning' );
4545
4646 }
4747
48+ // Edit user
4849 if (structKeyExists (form , " edit_user" )) {
4950 param name = " form.customer_id" default = " " ;
5051 param name = " form.user_id " default = " " ;
115116
116117 location url = " #application .mainURL #/sysadmin/customers/details/#form .customer_id #" addtoken = " false" ;
117118 }
119+
120+ // Add new customer
121+ if (structKeyExists (form , " add_customer" )) {
122+
123+ customerStruct = {};
124+ customerStruct [' strCompanyName' ] = form .company ;
125+ customerStruct [' strFirstName' ] = form .first_name ;
126+ customerStruct [' strLastName' ] = form .last_name ;
127+ customerStruct [' strEmail' ] = form .email ;
128+ customerStruct [' strLanguage' ] = form .language ;
129+ customerStruct [' password' ] = form .password ;
130+
131+ checkEmail = application .objGlobal .checkEmail (form .email );
132+
133+ if (checkEmail ) {
134+
135+ // Check for already registered email
136+ qCheckDouble = queryExecute (
137+ options = {datasource = application .datasource },
138+ params = {
139+ strEmail = {type : " nvarchar" , value : form .email }
140+ },
141+ sql = "
142+ SELECT intUserID
143+ FROM users
144+ WHERE strEmail = :strEmail
145+ "
146+ );
147+
148+ if (qCheckDouble .recordCount ) {
149+ getAlert (' This e-mail address is already in use!' , ' warning' );
150+ location url = " #application .mainURL #/sysadmin/customers" addtoken = " false" ;
151+ }
152+
153+ // Hash and salt the password
154+ hashedStruct = application .objGlobal .generateHash (form .password );
155+ customerStruct [' hash' ] = hashedStruct .this Hash ;
156+ customerStruct [' salt' ] = hashedStruct .this Salt ;
157+
158+ // Save the customer into the db
159+ objRegister = new frontend .core .com .register ();
160+ insertCustomer = objRegister .insertCustomer (customerStruct );
161+ if (insertCustomer .success ) {
162+
163+ qNewUser = queryExecute (
164+ options = {datasource = application .datasource },
165+ params = {
166+ strEmail = {type : " nvarchar" , value : form .email }
167+ },
168+ sql = "
169+ SELECT intCustomerID
170+ FROM users
171+ WHERE strEmail = :strEmail
172+ "
173+ );
174+
175+ newCustomerID = qNewUser .intCustomerID ;
176+
177+ // Update country or tinezone
178+ if (len (trim (form .countryID ))) {
179+
180+ queryExecute (
181+ options = {datasource = application .datasource },
182+ params = {
183+ intCustomerID : {type : " numeric" , value : newCustomerID },
184+ intCountryID : {type : " numeric" , value : form .countryID }
185+ },
186+ sql = "
187+ UPDATE customers
188+ SET intCountryID = :intCountryID
189+ WHERE intCustomerID = :intCustomerID
190+ "
191+ )
192+
193+ } else {
194+
195+ queryExecute (
196+ options = {datasource = application .datasource },
197+ params = {
198+ intCustomerID : {type : " numeric" , value : newCustomerID },
199+ intTimeZoneID : {type : " numeric" , value : form .timezoneID }
200+ },
201+ sql = "
202+ UPDATE customers
203+ SET intTimeZoneID = :intTimeZoneID
204+ WHERE intCustomerID = :intCustomerID
205+ "
206+ )
207+
208+ }
209+
210+ getAlert (' The new customer has been added.' , ' success' );
211+
212+
213+ } else {
214+
215+ getAlert (insertCustomer .message , ' danger' );
216+
217+ }
218+
219+ location url = " #application .mainURL #/sysadmin/customers" addtoken = " false" ;
220+
221+
222+
223+ }
224+
225+
226+
227+ }
228+
229+
230+
118231 </cfscript >
0 commit comments