This repository was archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_recruiting.php
527 lines (490 loc) · 18.5 KB
/
send_recruiting.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
<?php
use \Sizzle\Bacon\Database\{
EmailList,
EmailCredential,
RecruitingCompany,
RecruitingToken,
User
};
if (!logged_in()) {
login_then_redirect_back_here();
}
$user_id = (int) ($_SESSION['user_id'] ?? '');
$referrer = (int) ($_GET['referrer'] ?? '');
$recruiting_token_id = $_GET['id'] ?? '';
$token = new RecruitingToken($recruiting_token_id, 'long_id');
$company = new RecruitingCompany($token->recruiting_company_id);
$user = new User($user_id);
$credentials = (new EmailCredential())->getByUserId($user_id);
$lists = (new EmailList())->getByUserId($user_id);
define('TITLE', 'S!zzle - Send Recruiting Token');
require __DIR__.'/header.php';
?>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="/css/create_recruiting.min.css">
<!-- Polymer -->
<script src="/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="/components/iron-icons/iron-icons.html">
<link rel="import" href="/components/iron-icon/iron-icon.html">
<link rel="import" href="/components/iron-form/iron-form.html">
<link rel="import" href="/components/paper-menu/paper-menu.html">
<link rel="import" href="/components/paper-item/paper-item.html">
<link rel="import" href="/components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="/components/paper-input/paper-input.html">
<link rel="import" href="/components/paper-header-panel/paper-header-panel.html">
<link rel="import" href="/components/paper-toolbar/paper-toolbar.html">
<link rel="import" href="/components/paper-styles/paper-styles.html">
<link rel="import" href="/components/paper-card/paper-card.html">
<link rel="import" href="/components/paper-button/paper-button.html">
<link rel="import" href="/components/paper-input/paper-textarea.html">
<link rel="import" href="/components/paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="/components/paper-dialog/paper-dialog.html">
<link rel="import" href="/components/paper-fab/paper-fab.html">
<style is="custom-style">
.center-column {
margin-top: 100px;
}
.field-container {
text-align: left;
}
paper-card {
display: block;
width: 100%;
background: #424242;
margin-top: 20px;
--paper-card-header-color: white;
--paper-card-header-text: {font-weight: normal;}
}
paper-card#send-token-via {
display: none;
}
paper-input, paper-textarea, paper-dropdown-menu {
--paper-input-container-focus-color: #1094F7;
--paper-input-container-input-color: white
}
paper-button {
background: #009688;
color: white;
}
paper-button.dialog-button {
background: #2193ED;
font-size: 14px;
margin-top: 0px;
margin-bottom: 20px;
border: 0px;
}
.library-button {
margin: 10px 0px;
width: 100%;
}
iron-icon {
margin-right: 10px;
color: #676767;
}
paper-toolbar {
--paper-toolbar-background: #111111
}
#progress-bar {
width: 100%;
height: 70px;
padding: 7px 0px 0px 70px;
}
#token-strength {
width: 100%;
height: 300px;
}
paper-fab{
--paper-fab-background: #2193ED;
display: inline-block;
vertical-align: middle;
}
paper-fab.progress-fab {
margin-left: 10px;
}
paper-fab.current-fab {
margin-left: 10px;
}
paper-dialog {
--paper-dialog-background-color: #424242;
color: white;
--paper-dialog-title: {font-size: 24px; font-weight: 300; margin-top: 10px}
}
paper-dialog#status-dialog {
--paper-dialog-background-color: #303030;
}
.progress-text.active {
color: #009688;
}
#link-info {
height:260px;
}
#send-to-email-list, #send-to-email-credentials {
width:60%;
}
#send-token-button {
margin-top: 30px;
}
#social-shares {
margin-top:0px;
}
#facebook-share {
}
</style>
</head>
<body>
<div>
<?php require_once __DIR__.'/navbar.php';?>
</div>
<div class="center-column">
<paper-card id="progress-bar">
<a href="<?php echo '/create_recruiting?id='.$recruiting_token_id;?>">
<paper-fab icon="looks one" class="progress-fab">1</paper-fab>
</a>
<span class="progress-text">Job Info</span>
<div class="progress-line"></div>
<a href="<?php echo '/create_company?id='.$referrer.'&referrer='.$recruiting_token_id;?>">
<paper-fab icon="looks one" class="progress-fab"></paper-fab>
</a>
<span class="progress-text">Company Info</span>
<div class="progress-line"></div>
<paper-fab icon="looks one" class="progress-fab"></paper-fab>
<span class="progress-text active"><strong>Send Token</strong></span>
</paper-card>
<div id="left-column">
<paper-card id="link-info" heading="Share Token Link">
<div class="field-container">
<div class="pull-left" id="token-link" style="padding-top:15px;">
<a href="<?php echo APP_URL."token/recruiting/".$recruiting_token_id;?>" target="_blank">
<?php echo APP_URL."token/recruiting/".$recruiting_token_id;?>
</a>
</div>
<div class="pull-right" id="social-shares">
<paper-button
id="copy-link-button"
style="margin-left:0px"
raised
onclick="copyTokenLink()">
COPY</paper-button>
<a id="download-qr-code-link"><paper-button
id="download-qr-code-button"
style="margin-left:0px;"
raised
onclick="null">
Download QR Code
<div id="qr-code" hidden></div></paper-button></a>
<div id="li-root" style="margin-top:20px"></div>
<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
<script
type="IN/Share"
data-url="<?php echo APP_URL.'token/recruiting/'.$recruiting_token_id;?>">
</script>
<div id="tw-root" style="margin-top:10px"></div>
<script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));</script>
<a class="twitter-share-button"
href="https://twitter.com/intent/tweet?text=<?=urlencode($token->job_title)?>&url=<?=APP_URL.'token/recruiting/'.$recruiting_token_id?>"
>
Tweet</a>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5&appId=82256972765";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-share-button"
id="facebook-share"
data-href="<?=APP_URL.'token/recruiting/'.$recruiting_token_id?>"
data-layout="button">
</div>
</div>
</div>
</paper-card>
<h3>or</h3>
<paper-card id="send-to-info" heading="Send Via Email">
<div class="field-container">
<i>Send to an email or an email list.</i><br />
<paper-input
label="Email Address"
id="send-to-email"
hidden>
</paper-input>
<paper-button id="send-list-button" raised onclick="hideSingle()" hidden>EMAIL LIST</paper-button>
<paper-dropdown-menu
label="Choose Email List"
id="send-to-email-list">
<paper-menu class="dropdown-content">
<?php foreach ($lists as $list) {
echo '<paper-item value="'.$list['id'].'">'.$list['name'].'</paper-item>';
}?>
</paper-menu>
</paper-dropdown-menu>
<a id="new-list-button" href="/email_list?referrer=<?php echo $recruiting_token_id;?>">
<paper-button>NEW LIST</paper-button>
</a>
<paper-button id="send-single-button" raised onclick="hideList()" hidden>SINGLE EMAIL</paper-button>
<br />
<paper-dropdown-menu
label="Choose Email Credentials"
id="send-to-email-credentials"
on-iron-select="_itemSelected">
<paper-menu class="dropdown-content">
<?php foreach ($credentials as $credential) {
echo '<paper-item value="'.$credential['id'].'">'.$credential['credential'].'</paper-item>';
}?>
</paper-menu>
</paper-dropdown-menu>
<a href="/email_credentials?referrer=<?php echo $recruiting_token_id;?>">
<paper-button>NEW CREDENTIALS</paper-button>
</a>
<br />
<paper-input
label="Required Subject"
value="<?php echo $company->name ?> <?php echo $token->job_title ?>"
id="send-to-email-subject">
</paper-input>
<br />
<paper-textarea
label="Optional Message"
id="send-to-email-message"
rows="1">
</paper-textarea>
<br />
<paper-button id="send-token-button" raised onclick="sendEmails()">SEND</paper-button>
</div>
</paper-card>
</div>
<div id="right-column" class="pull-right">
<div class="button-container">
<paper-button raised onclick="backToCompany('<?php echo $referrer;?>', '<?php echo $recruiting_token_id;?>')">BACK</paper-button>
<?php if (is_admin()) { ?>
<paper-button raised onclick="uploadScreenshot()">ADD SCREENSHOT</paper-button>
<?php }?>
</div>
</div>
</div>
<paper-dialog class="recruiting-dialog" id="sent-dialog" modal>
<p id="sent-message">Your email(s) are being sent!</p>
<div class="button-container">
<paper-button dialog-dismiss id="ok-sent-button" hidden>OK</paper-button>
</div>
</paper-dialog>
<?php if (is_admin()) { ?>
<paper-dialog class="recruiting-dialog" id="upload-dialog" modal>
<h2>Upload Screenshot</h2>
<form id="description-upload">
<input class="hidden-file-input" type="file" id="select-list-file" name="listFile" hidden />
<paper-input id="upload-file" label="File Name" name="fileName" onclick="fireHiddenFileInput('#select-list-file')"></paper-input>
</form>
<i>Will replace existing screenshot</i>
<div class="">
<paper-button class="dialog-button" onclick="screenshotUpload()">UPLOAD</paper-button>
<paper-button dialog-dismiss class="dialog-button" onclick="cancelUpload()">CANCEL</paper-button>
</div>
</paper-dialog>
<paper-dialog class="recruiting-dialog" id="upload-process" modal>
<div id="upload-errors"></div>
<div class="">
<paper-button id="try-again-button" class="dialog-button" onclick="tryAgain()" hidden>TRY AGAIN</paper-button>
<paper-button id="cancel-again-button" dialog-dismiss class="dialog-button" onclick="cancelUpload()" hidden>CANCEL</paper-button>
<paper-button id="cancel-again-button" dialog-dismiss class="dialog-button" onclick="cancelUpload()" hidden>CANCEL</paper-button>
</div>
</paper-dialog>
<?php }?>
<?php require_once __DIR__.'/footer.php';?>
<!-- JavaScript -->
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<script>
/**
* Redirects user back to the company edit page
*
* @param {String} id The id of the company to go back to
* @param {String} token The long_id of the token to go back to
*/
function backToCompany(id, token) {
window.location = '/create_company?id='+id+'&referrer='+token;
}
/**
* Generates QR Code and adds to link for download.
*
*/
$("#qr-code").qrcode("<?php echo APP_URL."token/recruiting/".$recruiting_token_id;?>");
$("#download-qr-code-link")[0].href = $("#qr-code canvas")[0].toDataURL("image/png");
$("#download-qr-code-link")[0].download = "recruiting_token_qr_code.png";
/**
* Copies the token link to the keyboard
*/
function copyTokenLink() {
var $temp = $("<input>")
$("body").append($temp);
$temp.val($('#token-link a').text()).select();
document.execCommand("copy");
$temp.remove();
$('#copy-link-button').text('Copied!')
}
/**
* Replaces the email list option with a single email
*/
function hideList() {
$('#send-to-email-list').hide();
$('#new-list-button').hide();
$('#send-single-button').hide();
$('#send-to-email').removeAttr('hidden');
//$('#send-list-button').removeAttr('hidden');
}
/**
* Queues up the email(s) to be sent & informs users
*/
function sendEmails() {
$('#sent-dialog')[0].open();
$('#sent-message').html('Processing...');
$.ajax({
url: '/ajax/email/list/send/',
type: 'post',
data: {
token_id: '<?php echo $recruiting_token_id;?>',
email_list_id: $("#send-to-email-list paper-item[aria-selected='true']").attr('value'),
message: $('#send-to-email-message').val(),
email_credential_id: $("#send-to-email-credentials paper-item[aria-selected='true']").attr('value'),
subject: $('#send-to-email-subject').val(),
},
dataType: 'json',
success: function(data, textStatus){
//var message = data.data.message+'<br />';
if(data.success === 'true') {
$('#sent-message').html('Your emails were sent.');
} else if (typeof data.data.errors !== 'undefined') {
var height = 120;
var errors = '';
$.each(data.data.errors, function(i, v) {
errors += v+'<br/>';
height += 15;
});
$('#sent-dialog').css('height', height+'px');
$('#sent-message').html(errors);
} else {
$('#sent-message').html('Failed to send emails.');
}
$('#ok-sent-button').removeAttr('hidden');
}
}).fail(function() {
$('#sent-message').html('Failed to send emails.');
$('#ok-sent-button').removeAttr('hidden');
});
}
<?php if (is_admin()) { ?>
/**
* Opens the Upload Dialog
*/
function uploadScreenshot() {
$('#upload-dialog')[0].open();
}
/**
* Closes the Upload Dialog
*/
function cancelUpload() {
$('#upload-errors').html('');
$('#upload-dialog')[0].close();
$('#upload-process')[0].close();
}
/**
* Registers click on hidden file input.
*
* @param {String} identifier The jQuery identifier to click
*/
function fireHiddenFileInput(identifier) {
$(identifier).trigger('click');
}
/**
* Attempts to upload the job description to the ajax endpoint & presents success or error
*/
function screenshotUpload() {
var invalid = false;
if ('' == $('#upload-file').val()) {
$('#upload-file label').html('<font color="red">Please choose a file</font>');
invalid = true;
}
if (!invalid) {
$('#upload-dialog')[0].close();
$('#upload-errors').html('Processing...');
$('#upload-process')[0].open();
var formData = new FormData($('#description-upload')[0]);
if ($('#select-list-file')[0].files[0] !== undefined) {
var file = $('#select-list-file')[0].files[0];
var reader = new FileReader();
reader.fileName = '<?= $user_id.'_'.$token->id.'_'?>'+file.name;
reader.onloadend = function () {
var xhr = new XMLHttpRequest();
if (xhr.upload) {
xhr.open("POST", "/upload", true);
xhr.setRequestHeader("X-FILENAME", '<?= $user_id.'_'.$token->id.'_'?>'+file.name);
xhr.send(reader.result);
}
};
reader.readAsDataURL(file);
// save to table
$.post(
'/ajax/recruiting_token/set_screenshot',
{
'tokenId':'<?= $token->id?>',
'fileName':'<?= $user_id.'_'.$token->id.'_'?>'+file.name
},
function() {
// remove button
$('#screenshot').html('Screenshot has been uploaded');
$('#upload-errors').html('Screenshot has been uploaded');
$('#cancel-again-button').html('DISMISS');
$('#cancel-again-button').removeAttr('hidden');
}
).fail(function() {
$('#upload-errors').html('Uploading job description failed.');
$('#try-again-button').removeAttr('hidden');
$('#cancel-again-button').removeAttr('hidden');
});;
}
}
}
/**
* Reverts modal
*/
function tryAgain() {
$('#upload-process')[0].close();
$('#upload-dialog')[0].open();
//$('#upload-file').val('');
$('#try-again-button').attr('hidden','hidden');
$('#cancel-again-button').attr('hidden','hidden');
}
$( document ).ready(function() {
$('#select-list-file').change(function() {
var filename = $('#select-list-file').val().replace('C:\\fakepath\\', '');
/*if ($('#select-list-file:file')[0].files[0].type !== "text/plain") {
$('#upload-file label').html('<font color="red">Please choose a text file</font>');
$('#upload-file').val('');
} else {*/
$('#upload-file label').html('File Name');
$('#upload-file').val(filename);
//}
});
});
<?php }?>
</script>
</body>
</html>