-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvendorAdmin.php
575 lines (534 loc) · 21.9 KB
/
vendorAdmin.php
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<?
$ssid=0;
if (isset($_REQUEST['ssid'])){
$ssid=$_REQUEST['ssid'];
session_id($ssid);
$ssidLink_continuing = "&ssid=".$ssid;
$ssidLink_starting = "?ssid=".$ssid;
}
session_start();
/*echo "Session info: <br>";
print_r($_SESSION);
echo "<br><br>";*/
include_once('vendorsClass.php');
$vpc = new vendorsClass('vendorList.xml');
$username = "";
$isAdmin = false;
$vendor = NULL;
$valid_login = false;
if (isset($_SESSION['username'])){
$valid_login=true;
$username = $_SESSION['username'];
$vendor = $vpc->findVendorWithEmail($username);
if (!is_null($vendor))
$isAdmin = $vendor->isAdmin();
}
//else echo "Warning Session Didn't Set<br>";
?>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<title>Vendor Administration</title>
<script src="scripts/jquery/jquery-1.11.2.min.js"></script>
<link href="html5reset-1.6.1.css" rel="stylesheet" type="text/css">
<link href="vendorAdmin.css" rel="stylesheet" type="text/css">
<link href="privateVendorPages.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<h1>St. Louis Bridal Professionals</h1>
<p id="homeLink"><a href="http://www.stlbridalpros.com">Home</a></p>
<br>
<p class="activeStatus">
<?
if ($valid_login){
$postingStatusOnImg = "images/off_101x119.png";
if ($vendor->canVendorBePosted()){
$postingStatusOnImg = "images/on_101x119.png";
}
?>
Your Web Status is: <img src="<?=$postingStatusOnImg?>"/>
<?
}else{ //this case of not logging in is taken care of at the bottom of the page
?>
<!--Something didn't load right, try refresing or logging in again. If the problem persists contact the site administrator.-->
<?
}
?>
</p>
</header>
<?
if ($valid_login && $isAdmin){
?>
<section class="adminOnlyFunctions">
<div class="functionWrapper">
<p class="sectionHeaderText">Administrative Operations</p>
<p class="functionHeader">Create New User</p>
<p class="functionBounds hidden">
<span>
<label class="functionLabel" for="createNewVendor">Enter Business Email:</label>
<input type="text" class="dataInput" id="createNewVendor" name="createNewVendor" value=""/>
</span>
<span>
<label class="functionLabel spaceAbove" for="createNewVendorBizName">Enter Business Name:</label>
<input type="text" class="dataInput" id="createNewVendorBizName" name="createNewVendorBizName" value=""/>
</span>
<span>
<label class="functionLabel spaceAbove" for="vendorType">Vendor Type:</label>
<?
$vtClass = new VENDORTYPE();
$vtSelect = $vtClass->getSelectCode("vendorType","vendorTypeClass",$usingVendor,false);
echo $vtSelect;
?>
</span>
<span>
<label class="functionLabel spaceAbove" for="vendorType">Vendor Type:</label>
<?
$vtMembershipClass = new VENDORMEMBERSHIPTYPE();
$vtMembershipSelect = $vtMembershipClass->getSelectCode("vendorMembershipType","vendorMembershipTypeClass",$usingVendor,false);
echo $vtMembershipSelect;
?>
</span>
<br>
<input class="spaceAboveButton" type="button" id="createNewVendorButton" value="Create New Vendor"/>
</p>
<p class="functionHeader">Edit User</p>
<p class="functionBounds hidden">
<label class="functionLabel" for="editVendorSelect">Select Vendor To Edit:</label>
<?=$vpc->getSelectCode('name','editVendorSelect','dataInput',true,"");?>
<br>
<input class="spaceAboveButton" type="button" id="editVendorButton" value="Edit Vendor"/>
</p>
<p class="functionHeader">Remove User</p>
<p class="functionBounds hidden">
<label class="functionLabel" for="editVendorSelect">Select Vendor To Remove:</label>
<?=$vpc->getSelectCode('name','removeVendorSelect','dataInput',true,"");?>
<br>
<input class="spaceAboveButton" type="button" id="removeVendorButton" value="Remove Vendor"/>
</p>
<p class="functionHeader">Set User Access</p>
<p class="functionBounds hidden">
<label class="functionLabel" for="setAdminStatusSelect">Select Vendor:</label>
<?=$vpc->getSelectCode('name','setAdminStatusSelect','dataInput',true,"");?>
<br>
<span id="adminChoiceBlock" class="spaceAbove hidden">
<label class="functionLabel" for="adminChoice">Select Access Level:</label>
<SELECT class="adminChoiceClass" name="adminChoice" id="adminChoice">
<option value="yes">admin</option>
<option value="no">user</option>
</SELECT>
<br>
<input id="updateAccessLevelBtn" class="spaceAboveButton" type="button" value="Update Access Level"/>
</span>
</p>
<p class="functionHeader">Set User Type</p>
<p class="functionBounds hidden">
<label class="functionLabel" for="setVendorTypeSelect">Select Vendor:</label>
<?=$vpc->getSelectCode('name','setVendorTypeSelect','dataInput',true,"");?>
<br>
<span class="changeVendorTypeBlock" class="spaceAbove hidden">
<label class="functionLabel spaceAbove" for="vendorChangeTypeSelect">Type:</label>
<?
$vtChangeClass = new VENDORTYPE();
$vtChangeSelect = $vtChangeClass->getSelectCode("vendorChangeTypeSelect","vendorChangeTypeClass",$usingVendor,true,"","");
echo $vtChangeSelect;
?>
</span>
<br>
<span class="changeVendorTypeBlock" class="spaceAbove hidden">
<label class="functionLabel spaceAbove" for="vendorChangeMembershipTypeSelect">Membership Type:</label>
<?
$vtChangeMembershipClass = new VENDORMEMBERSHIPTYPE();
$vtChangeMembershipSelect = $vtChangeMembershipClass->getSelectCode("vendorChangeMembershipTypeSelect","vendorChangeMembershipTypeClass",$usingVendor,true,"","");
echo $vtChangeMembershipSelect;
?>
</span>
<br>
<span class="changeVendorTypeBlock" class="spaceAbove hidden">
<input id="updateVendorTypeLevelBtn" class="spaceAboveButton" type="button" value="Update Vendor Type Fields"/>
</span>
</p>
<p class="functionHeader">Set Users Web Display Order</p>
<p class="functionBounds hidden"><a href="http://www.stlbridalpros.com/sortVendors.php<?=$ssidLink_starting?>">arrange order of vendors</a></p>
<p class="functionHeader">Modify Website 'About' Text</p>
<p class="functionBounds hidden"><input id="editGroupAboutText" type="button" value="Edit Group's About Text" onClick="showEditText(this,'stlbridalprosAboutText.txt');"/><input class="hidden" id="saveGroupAboutText" type="button" value="Save About Text" onclick="saveEditText(this,'stlbridalprosAboutText.txt');"/><input class="cancelEditTextButton hidden" type="button" value="Cancel" onClick="cancelEditText(this);"/><textarea id="aboutTextArea" contentEditable="true" class="hidden textGoesHere"></textarea></p>
<p class="functionHeader">Modify Website 'Ticket To Savings' Text</p>
<p class="functionBounds hidden"><input id="editGroupTicketToSavingsText" type="button" value="Edit Group's Ticket To Savings Text" onClick="showEditText(this,'aboutTicketToSavingsText.txt');"/><input class="hidden" id="saveGroupTicketToSavingsText" type="button" value="Save Ticket To Savings Text" onclick="saveEditText(this,'aboutTicketToSavingsText.txt');"/><input class="cancelEditTextButton hidden" type="button" value="Cancel" onClick="cancelEditText(this);"/><textarea id="tkts2SavingsTextArea" contentEditable="true" class="hidden textGoesHere"></textarea></p>
<p class="functionHeader">Re-Send Welcome Email</p>
<p class="functionBounds hidden">
<label class="functionLabel" for="sendWelcomeEmail">Select Vendor To Email:</label>
<?=$vpc->getSelectCode('name','welcomeEmailSelect','dataInput',true,"");?>
<br>
<input class="spaceAboveButton" type="button" value="Send Email" onClick="sendWelcomeEmail();"/>
</p>
</div>
</section>
<?
} //end if Admin
?>
<section class="userFunctions">
<?
if ($valid_login && (!is_null($vendor))){
?>
<div class="functionWrapper">
<p class="sectionHeaderText">User Operations</p>
<p class="functionHeader">Edit User Profile</p>
<p class="functionBounds hidden">
<input class="" type="button" id="editUserButton" value="Click To Edit Profile"/>
</p>
<p class="functionHeader">Useful Downloads</p>
<p class="functionBounds hidden">
<a href="http://www.stlbridalpros.com/downloadSTLGroupLogos.php<?=$ssidLink_starting?>">Download Arch Logo</a>
<br>
<a href="http://www.stlbridalpros.com/downloadSTLOtherItems.php<?=$ssidLink_starting?>">Download Other Items</a>
<br>
<a href="http://www.stlbridalpros.com/downloadVendorLogos.php<?=$ssidLink_starting?>">Download Eachother's Logos</a>
</p>
<p class="functionHeader">Change Password</p>
<p class="functionBounds hidden">
<span class="changePasswordWarningText warningColor hidden" id="oldPasswordIncorrect">The old password was not correct<br></span>
<span class="changePasswordWarningText warningColor hidden" id="passwordsDoNotMatch">The new passwords do not match<br></span>
<span class="changePasswordWarningText warningColor hidden" id="blankNewPassword">The new password cannot be blank<br></span>
<span class="changePasswordWarningText warningColor hidden" id="passwordLengthProblem">The new password must be between 4-20 letters or numbers<br></span>
<span>
<label class="functionLabel spaceAbove" for="oldPassword">Old Password:</label>
<input type="password" class="dataInput" id="oldPassword" name="oldPassword" value=""/>
</span>
<span>
<label class="functionLabel spaceAbove" for="newPassword">New Password:</label>
<input type="password" class="dataInput" id="newPassword" name="newPassword" value=""/>
</span>
<span>
<label class="functionLabel spaceAbove" for="newPasswordVerify">Re-Type New Password:</label>
<input type="password" class="dataInput" id="newPasswordVerify" name="newPasswordVerify" value=""/>
</span>
<input class="spaceAboveButton" type="button" id="changePasswordButton" value="Change Password"/>
</p>
<?
if (!$vendor->canVendorBePosted()){
?>
<p class="functionHeader">Why Is My Web Status Off?</p>
<p class="functionBounds hidden">
<input id="statusReasonsBtn" type="button" value="Show/Refresh Reasons"/>
<br>
<span id="statusReasons">
</span>
</p>
<?
}//end if vendor can't be posted
?>
<br><br><p><b>Eventually coming functions</b><p>
<p>download minutes</p>
<p>team calendar</p>
<p>preview landing page</p>
<p>switch status on off</p>
</div>
<?
}else{ //end check if Vendor was null
echo '<span class="warningColor">Unable to login, try logging in again at: <a href="http://www.stlbridalpros.com/vendorLogin.php">www.stlbridalpros.com/vendorlogin.php</a></span>';
}
?>
</section>
<script>
function sendWelcomeEmail(id,email){
var reloadNeeded = (id)?true:false;
var vendorID = (id)?id:$("#welcomeEmailSelect").val();
var mailSentTo = (email)?email:$("#welcomeEmailSelect option:selected" ).text();
if ($(vendorID) != "-1"){
$.ajax({url:'sendWelcomeEmail.php',
type:'POST',
dataType:"json",
data:{vendorID:vendorID,ssid:'<?=$ssid?>'}
})
.done(function(success){
if (success == true){
$("#welcomeEmailSelect").val("-1");
alert("Welcome email sent to: "+mailSentTo);
if (reloadNeeded){
location.reload(true);
}
}else{
alert("Error Sending Welcome Email.\nMessage: "+success.message);
}
});
}
}
function cancelEditText(buttonClicked){
var textArea = $(buttonClicked).parent().find("textarea");
$(buttonClicked).parent().find("input").toggleClass("hidden");
$(textArea).addClass("hidden");
}
function showEditText(buttonClicked,fileToRead){
$(buttonClicked).parent().find(".hidden").removeClass("hidden");
$(buttonClicked).addClass("hidden");
$.ajax({url:'getFileContents.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:"html",
data:{fileToGet:fileToRead,ssid:'<?=$ssid?>'}
})
.done(function(contents){
//var contents = decodeURI(contents);
$(buttonClicked).parent().find(".textGoesHere").val(contents);
});
};
function saveEditText(buttonClicked,fileToSave){
var textArea = $(buttonClicked).parent().find("textarea");
var textToSave = $(textArea).val();
$(buttonClicked).parent().find(".hidden").removeClass("hidden");
$(textArea).addClass("hidden");
$(buttonClicked).addClass("hidden");
$.ajax({url:'saveFileWithContents.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:"json",
data:{fileToWrite:fileToSave,contents:textToSave,ssid:'<?=$ssid?>'}
})
.done(function(success){
if (success){
alert("Saved");
}else{
alert("Problems Saving");
}
});
};
function initializeEvents(){
$(".functionHeader").on("click",function(){
var clickedOnFH = $(this);
$(".functionHeader").each(function(){
if ($(this).get(0) == $(clickedOnFH).get(0)){
$(this).next().toggleClass("hidden");
}else{
$(this).next().addClass("hidden");
}
});
});
$("#statusReasonsBtn").on("click",function(){
$.ajax({url:'getNoPostingReasons.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:'json',
data:{vendorID:'<?=$vendo->id?>',
ssid:'<?=$ssid?>'}
})
.done(function(completed){
if (completed.success == true){
$htmlString = '<ul>';
for(var reasonCount in completed.reasons){
$htmlString += '<li>'+completed.reasons[reasonCount]+'</li>';
}
$htmlString += '</ul>';
$("#statusReasons").html($htmlString);
}else{
$("#statusReasons").html("unable to retrieve reasons");
}
});
});
$("#removeVendorButton").on("click",function(){
$.ajax({url:'removeVendor.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:'json',
data:{vendorID:$("#removeVendorSelect").val(),
ssid:'<?=$ssid?>'}
})
.done(function(removed){
$("#removeVendorSelect").val("-1");
if (removed == true){
alert("Vendor Was Removed.");
}else{
alert("Vendor Was Not Removed.");
}
location.reload(true);
});
});
$("#createNewVendorButton").on("click",function(){
$.ajax({url:'createNewVendor.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:'json',
data:{email:$("#createNewVendor").val(),bizName:$("#createNewVendorBizName").val(),
vendorType:$("#vendorType").val(),vendorMembershipType:$("#vendorMembershipType").val(),
ssid:'<?=$ssid?>'}
})
.done(function(created){
if (created == false){
alert("New Vendor Not Created");
}else{
$("#createNewVendor").val("");
$("#createNewVendorBizName").val("");
$("#vendorType").val('<?=VENDORTYPE::NONVENUE?>');
$("#vendorMembershipType").val('<?=VENDORMEMBERSHIPTYPE::FULLMEMBER?>');
//do code to send an email
sendWelcomeEmail(created.id,created.email);
}
});
});
$("#setVendorTypeSelect").on("change",function(){
//var setVendorTypeSelect = $("#setVendorTypeSelect");
var changeVendorTypeSelect = $("#vendorChangeTypeSelect");
var changeVendorMembershipTypeSelect = $("#changeVendorMembershipTypeSelect");
var changeVendorTypeBlock = $(".changeVendorTypeBlock");
var vendorID = $(this).val();
if (vendorID != "-1"){
$.ajax({url:'getVendorTypes.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:'json',
data:{id:vendorID}
})
.done(function(vendorTypes){
$(changeVendorTypeSelect).val(vendorTypes.vendorType);
$(changeVendorMembershipTypeSelect).val(vendorTypes.vendorMembershipType);
$(changeVendorTypeBlock).removeClass("hidden");
});
}else//vendor is blank
$(changeVendorTypeBlock).addClass("hidden");
});
$("#updateVendorTypeLevelBtn").on("click",function(){
var vendorID = $("#setVendorTypeSelect").val();
var vendorType = $("#vendorChangeTypeSelect").val();
var vendorMembershipType = $("#vendorChangeMembershipTypeSelect").val();
$.ajax({url:'updateVendorTypes.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:'json',
data:{vendorID:vendorID,vendorType:vendorType,vendorMembershipType:vendorMembershipType,ssid:'<?=$ssid?>'}
})
.done(function(completed){
$("#setVendorTypeSelect").val("-1");
$(".changeVendorTypeBlock").addClass("hidden");
if (completed){
alert("Vendor Types updated.");
}else{
alert("Unable to update vendor types.");
}
});
});
$("#setAdminStatusSelect").on("change",function(){
var adminSelect = $("#adminChoice");
var adminChoiceBlock = $("#adminChoiceBlock");
var vendorID = $(this).val();
if (vendorID != "-1"){
$.ajax({url:'isVendorAnAdmin.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:'json',
data:{id:vendorID}
})
.done(function(isAdmin){
if (isAdmin == true)
$(adminSelect).val("yes");
else
$(adminSelect).val("no");
$(adminChoiceBlock).removeClass("hidden");
});
}else//vendor is blank
$(adminChoiceBlock).addClass("hidden");
});
$("#updateAccessLevelBtn").on("click",function(){
var vendorID = $("#setAdminStatusSelect").val();
var adminStatus = $("#adminChoice").val();
$.ajax({url:'updateAdminStatus.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:'json',
data:{id:vendorID,adminStatus:adminStatus,ssid:'<?=$ssid?>'}
})
.done(function(completed){
$("#setAdminStatusSelect").val("-1");
$("#adminChoiceBlock").addClass("hidden");
if (completed){
alert("Admin status updated.");
}else{
alert("Unable to update admin status.");
}
});
});
$("#changePasswordButton").on("click",function(){
var oldPassword = $("#oldPassword").val();
var newPassword = $("#newPassword").val();
var newPasswordVerify = $("#newPasswordVerify").val();
var changePasswordValid = true;
var savedPassword = '';
$.ajax({url:'getPassword.php',
type:'POST',
async:false,
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:"html",
data:{ssid:'<?=$ssid?>'}
})
.done(function(contents){
//var contents = decodeURI(contents);
savedPassword = contents;
});
if (oldPassword == savedPassword){
if (newPassword == newPasswordVerify){
if (newPassword == ""){
showChangePasswordError("blankNewPassword");
changePasswordValid = false;
}
var passwordPattern = /[a-zA-Z0-9]{4,20}/;
if (!passwordPattern.test(newPassword)){
showChangePasswordError("passwordLengthProblem");
changePasswordValid = false;
}
}else{
showChangePasswordError("passwordsDoNotMatch");
changePasswordValid = false;
}
}else{
showChangePasswordError("oldPasswordIncorrect");
changePasswordValid = false;
}
if (changePasswordValid){
$.ajax({url:'updatePassword.php',
type:'POST',
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
dataType:'json',
data:{password:newPassword,ssid:'<?=$ssid?>'}
})
.done(function(completed){
showChangePasswordError();
$("#oldPassword").val('');
$("#newPassword").val('');
$("#newPasswordVerify").val('');
if (completed){
alert("Password updated.");
}else{
alert("Unable to update password.");
}
});
}
});
$("#editVendorButton").on("click",function(){
window.location.href = "http://www.stlbridalpros.com/editVendor.php?user_id="+$("#editVendorSelect").val()+"<?=$ssidLink_continuing?>";
});
$("#editUserButton").on("click",function(){
window.location.href = "http://www.stlbridalpros.com/editVendor.php?user_id="+<?=$vendor->id?>+"<?=$ssidLink_continuing?>";
});
}
function showChangePasswordError(errorToShow){
clearAllPasswordErrors();
if ((errorToShow != "") && ($("#"+errorToShow).length > 0))
$("#"+errorToShow).removeClass("hidden");
}
function clearAllPasswordErrors(){
$("#oldPasswordIncorrect").addClass("hidden");
$("#passwordsDoNotMatch").addClass("hidden");
$("#blankNewPassword").addClass("hidden");
$("#passwordLengthProblem").addClass("hidden");
}
$( document ).ready(function() {
initializeEvents();
<?
if ($isAdmin){
?>
$("#vendorType").val('<?=VENDORTYPE::NONVENUE?>');
$("#vendorMembershipType").val('<?=VENDORMEMBERSHIPTYPE::FULLMEMBER?>');
<?
}
?>
});
</script>
</body>
</html>