-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcompany.php
More file actions
343 lines (313 loc) · 15.6 KB
/
company.php
File metadata and controls
343 lines (313 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php include('include/header.php'); ?>
<!-- Breadcrumbs-->
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="index.php">Dashboard</a>
</li>
<li class="breadcrumb-item active">Company-info</li>
</ol>
<div class="card">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs">
<li class="nav-item">
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-company" role="tab" aria-controls="nav-home" aria-selected="true">Company-info</a>
</li>
</ul>
</div>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-company" role="tabpanel" aria-labelledby="nav-home-tab">
<div class="card-body">
<div class="form-group">
<h4>Company Information</h4>
<hr class="colorgraph">
<form id="update_company_form">
<div class="row">
<div class="col-sm-12 col-md-6">
<div class="form-group">
<label>Company Name <i class="text-danger">*</i></label>
<input type="text" class="form-control" id="company_name" name="company_name" maxlength="100" placeholder="Enter company name">
<div id="company_name_error_message" class="text-danger"></div>
</div>
<div class="form-group">
<label>Website</label>
<input type="text" class="form-control" id="website" name="website" maxlength="100" placeholder="Enter website url">
<div id="website_error_message" class="text-danger"></div>
</div>
<div class="form-group">
<label>E-mail</label>
<input type="text" class="form-control" id="email" name="email" maxlength="100" placeholder="Enter email">
<div id="email_error_message" class="text-danger"></div>
</div>
<div class="form-group">
<label>Address</label>
<textarea id="address" name="address" class="form-control" rows="2" maxlength="500" autocomplete="off" placeholder="Enter address"></textarea>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label>City</label>
<input type="text" class="form-control" id="city" name="city" maxlength="100" placeholder="Enter city">
</div>
<div class="form-group col-md-4">
<label>Country</label>
<input type="text" class="form-control" id="country" name="country" maxlength="100" placeholder="Enter country">
</div>
<div class="form-group col-md-4">
<label>Postal/Zip Code</label>
<input type="text" class="form-control" id="zip_code" name="zip_code" maxlength="100" placeholder="Enter zip code">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Phone</label>
<input type="text" class="form-control" id="phone" name="phone" maxlength="100" placeholder="Enter phone">
</div>
<div class="form-group col-md-6">
<label>Fax</label>
<input type="text" class="form-control" id="fax" name="fax" maxlength="100" placeholder="Enter fax">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Vat Number</label>
<input type="text" class="form-control" id="vat_number" name="vat_number" maxlength="100" placeholder="Enter vat number">
</div>
<div class="form-group col-md-6">
<label>Company Number</label>
<input type="text" class="form-control" id="company_number" name="company_number" maxlength="100" placeholder="Enter company number">
</div>
</div>
<div class="modal-footer">
<button type="button" id="cancel_button" class="btn btn-light">Cancel</button>
<input type="submit" id="update_profile_button" name="update_profile_button" class="btn btn-primary" value="Update" />
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="container">
<br/>
<label>Company Logo</label>
<div class="panel panel-default">
<div class="panel-body">
<div id="uploaded_image"></div>
<br>
<label class="btn btn-primary">
Upload Company Logo<input type="file" name="upload_image" id="upload_image" style="display: none;" accept="image/*">
</label>
<br/>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Upload company logo -->
<div id="upload_image_modal" class="modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Crop and Upload Company Logo</h5>
<button class="close" data-dismiss="modal">
<span>×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12 text-center">
<div id="image_demo"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Close</button>
<input type="submit" id="update_logo_button" name="update_logo_button" class="btn btn-primary update_logo_button" value="Update" />
<!-- <input type="submit" id="update_profile_button" name="update_profile_button" class="btn btn-primary" value="Update" /> -->
</div>
</div>
</div>
</div>
<!--./ Upload company logo -->
<?php include 'include/footer.php'; ?>
<script>
$(document).ready(function () {
getCompany();
bringCompanyLogo();
var error_company_name = false;
var error_email = false;
var error_website = false;
$("#company_name").keyup(function() {
check_company_name();
});
$("#email").keyup(function () {
check_email();
});
$("#website").keyup(function() {
check_website();
});
// Validate company name.
function check_company_name() {
if( $.trim( $('#company_name').val() ) == '' ){
$("#company_name_error_message").html("Company name is a required field.");
$("#company_name_error_message").show();
$("#company_name").addClass("is-invalid");
error_company_name = true;
} else {
$("#company_name_error_message").hide();
$("#company_name").removeClass("is-invalid");
}
}
// Validate email
function check_email() {
var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
var email_length = $("#email").val().length;
if ($.trim($('#email').val()) == ''){
$("#email_error_message").hide();
$("#email").removeClass("is-invalid");
}else if (!(pattern.test($("#email").val()))){
$("#email_error_message").html("Invalid email address.");
$("#email_error_message").show();
$("#email").addClass("is-invalid");
error_email = true;
}else{
error_email = false;
$("#email_error_message").hide();
$("#email").removeClass("is-invalid");
}
}
// Validate URL
function check_website() {
var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
var website = $("#website").val();
if( $.trim( $('#website').val() ) == '' ){
$("#website_error_message").hide();
$("#website").removeClass("is-invalid");
}else if(!website.match(pattern)) {
$("#website_error_message").html("Enter a valid URL.");
$("#website_error_message").show();
$("#website").addClass("is-invalid");
error_website = true;
} else{
$("#website_error_message").hide();
$("#website").removeClass("is-invalid");
}
}
$('#cancel_button').click(function(){
swal({
title: "Are you sure?",
text: "",
icon: "warning",
buttons: ["No", "Yes, cancel!"],
dangerMode: true,
}).then((willDelete) => {
if (willDelete) {
location.reload();
}
});
});
// Bring company information.
function getCompany() {
$.ajax({
url: "company_action.php",
type: "POST",
data: {action: 'fetch_company'},
success: function (data) {
data = JSON.parse(data);
$('#company_name').val(data.company_name);
$('#website').val(data.company_website);
$('#email').val(data.company_email);
$('#address').val(data.company_address);
$('#city').val(data.company_city);
$('#country').val(data.company_country);
$('#zip_code').val(data.company_zip_code);
$('#phone').val(data.company_phone);
$('#fax').val(data.company_fax);
$('#vat_number').val(data.company_vat_number);
$('#company_number').val(data.company_number);
}
});
}
// Update company information
$('#update_company_form').on('submit', function (event) {
event.preventDefault();
error_company_name = false;
error_email = false;
error_website = false;
check_company_name();
check_email();
check_website();
if (error_company_name == false && error_email == false && error_website == false) {
$.ajax({
url:"company_action.php",
type:"POST",
data: $('#update_company_form').serialize()+'&action=update_company',
beforeSend:function(){
$('#update_profile_button').val('Please wait...');
$('#update_profile_button').attr('disabled', 'disabled');
$('#cancel_button').attr('disabled', 'disabled');
},success:function(data){
data = JSON.parse(data);
swal("Success!", data.message, "success");
getCompany();
$('#update_profile_button').val('Update');
$('#update_profile_button').attr('disabled', false);
$('#cancel_button').attr('disabled', false);
},error:function(){
swal("Oops..!", "Something went wrong.", "error");
$('#update_profile_button').val('Save');
$('#update_profile_button').attr('disabled', false);
$('#cancel_button').attr('disabled', false);
}
});
}
});
// Upload company logo
$image_crop = $('#image_demo').croppie({
enableExif: true,
viewport: {
width:200,
height:200,
type:'square'
},
boundary:{
width:300,
height:300
}
});
$('#upload_image').on('change', function(){
var reader = new FileReader();
reader.onload = function (event) {
$image_crop.croppie('bind', {
url: event.target.result
})
}
reader.readAsDataURL(this.files[0]);
$('#upload_image_modal').modal('show');
});
$('.update_logo_button').click(function(event){
$image_crop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function(response){
$.ajax({
url:"company_action.php",
type:"POST",
data: {"image": response, action: 'update_company_logo'},
success:function(data) {
console.log(data);
$('#upload_image_modal').modal('hide');
location.reload();
},error:function(){
swal("Oops..!", "Something went wrong.", "error");
}
});
})
});
// Bring Company Logo
function bringCompanyLogo(){
$('#uploaded_image').html('<img src="images/company_logo.png" class="img-thumbnail" />');
}
});
</script>