-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.cgi
More file actions
executable file
·671 lines (600 loc) · 17.1 KB
/
query.cgi
File metadata and controls
executable file
·671 lines (600 loc) · 17.1 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
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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
#!/usr/bin/perl -w
# Copyright(c) 2003-2007 Robert L. Brown. This is licensed software
# only to be used with an explicit right-to-use license from the
# copyright holder.
use Getopt::Std;
use CGI qw(:standard -nosticky *table *Tr *td);
use CGI::Carp qw(fatalsToBrowser);
use Data::Dumper;
require "globals.pl";
use UserTable;
use ActionTable;
use OpeningTable;
use CandidateTable;
use DepartmentTable;
use Application;
use Query;
use Database;
use Layout;
use Login;
use Candidate;
use User;
use Comment;
use Utility;
my @Standard = (
{
heading => "ID",
url => "id",
field => 'id',
align => "right",
},
{
heading => "Name",
url => 'name',
field => 'name',
link => \&Candidate::candidateURL,
warpable => 1, # means that this url can be warped to if only one result is returned
},
{
heading => "Status",
url => 'status',
field => 'status',
},
{
heading => "Next Action",
url => 'action_id',
field => 'action_id.action',
},
{
heading => "Owner",
url => 'owner',
field => 'owner_id.name',
},
{
heading => "Age",
url => 'age',
field => 'agestr',
nowrap => "1",
},
{
heading => "Rating",
url => 'ratings',
field => 'ratingstr',
align => "left",
expand => 'userratings'
},
{
heading => "Coms",
url => 'comments',
field => 'commentstr',
align => "left",
expand => "usercomments",
},
{
heading => "Docs",
url => 'documents',
field => 'documents',
align => "center",
},
{
heading => "Info?",
field => 'havecontact',
align => "center",
type => "YN",
},
{
heading => "Position",
url => 'position',
field => 'opening_id.description',
},
{
heading => "Referred By",
value => \&Candidate::getReferrer,
field => "referrer",
url => "referrer",
},
);
my @Recruiter = (
{
heading => "ID",
url => "id",
field => 'id',
align => "right",
},
{
heading => "Name",
url => 'name',
field => 'name',
# link => \&Candidate::candidateURL,
warpable => 1, # means that this url can be warped to if only one result is returned
},
{
heading => "Status",
url => 'status',
field => 'status',
},
{
heading => "Next Action",
url => 'action_id',
field => 'action_id.action',
},
{
heading => "Age",
url => 'age',
field => 'agestr',
nowrap => "1",
},
{
heading => "Info?",
field => 'havecontact',
align => "center",
type => "YN",
},
{
heading => "Position",
url => 'position',
field => 'opening_id.description',
},
{
heading => "Referred By",
value => \&Candidate::getReferrer,
url => "referrer",
field => "referrer",
},
{
heading => "Ref #",
field => "recruiter_ref",
align => "right",
},
);
my %Format = (
"standard" => {
columns => \@Standard,
nolinks => 0,
},
"recruiter" => {
columns => \@Recruiter,
nolinks => 1,
},
"long" => {
columns => \@Standard,
nolinks => 0,
},
);
Application::Init();
# In must-log-in mode, make sure we're logged in
my $mustLogIn = Param::getValueByName('must-log-in');
if ( $mustLogIn && ref $mustLogIn ) {
$mustLogIn = $mustLogIn->{'value'};
}
if ( $mustLogIn && !isLoggedIn() ) {
doMustLogin(url(-absolute => 1, -query=>1));;
}
if ( param("op") && param("op") eq "go" ) {
doGo();
exit(0);
}
if ( param("op") ) {
my $op = param("op");
SWITCH: {
$op eq "query" and do {
doQuery();
last SWITCH;
};
};
} else {
doFirstPage();
}
exit(0);
sub doFirstPage
{
print header;
ConnectToDatabase();
my $jscript = Query::getJavaScript();
print doHeading({-title=>"Query Candidates",
-script=>$jscript,
-onload=>"selectDepartment(document.forms['queryform']);"});
## Make query form
print Layout::startForm({-name=>"queryform"});;
print hidden({-name=>"op", -default=>"go"});
print Query::standardForm("queryform");
print table({-cellpadding=>3},
Tr(
td({-valign=>"top", -align=>"right"}, b("Group by: ")),
td({-valign=>"top"}, radio_group({-name=>"groupby",
-values=>["none", "action", "status"],
-labels=>{'none'=>"None",
'action'=>"Next Action",
'status'=>"Status"},
-linebreak=>1
})),
td(" "),
td({-valign=>"top", -align=>"right"}, b("Format: ")),
td({-valign=>"top"}, radio_group({-name=>"format",
-values=>['standard', 'recruiter', 'long'],
-linebreak=>'true',
-labels=>{'standard'=>"Standard",
'recruiter'=>"Recruiter",
'long'=>"Long"}})),
td({-valign=>"top"},checkbox({-name=>"nolinks", -value=>1, -label=>"Omit all links (default for recruiter mode)"}))
));
print br(),submit({-name=>"Search"}), " ", reset({-name=>"Clear Form"}), "\n";
print Layout::endForm;
print Footer(),"\n";
print end_html, "\n";
}
sub doGo
{
my $q = new CGI;
$q->param("op", "query");
$q->delete("Search");
print $q->redirect(-location=>$q->url(-absolute => 1, -query=>1), -method=>"get");
}
##
## Process the "Search" command from the main query page
##
sub doQuery
{
my $lastURL = undef;
my $format = param("format");
if ( !defined $format ) {
$format = "standard";
}
my $self_url = url(-absolute => 1, -query=>1);
my $groupby = param("groupby");
my $sort = param("sort");
my $sortorder = param("sortorder");
my $expand = param("expand");
my $param_sort = param("sort");
my $param_sortorder = param("sortorder");
my $param_groupby = param("groupby");
if (defined $groupby && $groupby ne "none") {
## If sorting by something other than action is defined, override the group by parameters
if ( defined $sort ) {
if ( $groupby eq 'action' ) {
if ( $sort !~ /^action_id/ ) {
$groupby = undef
}
} elsif ( $groupby eq 'status' ) {
if ( $sort !~ /^status/ ) {
$groupby = undef
}
}
} else {
if ( $groupby eq 'action' ) {
$sort = "action_id.precedence-n";
} elsif ( $groupby eq 'status' ) {
$sort = 'status';
}
}
} else {
# $groupby = undef;
}
## These are the sort urls for the column headings
my %sorturl;
my $nolinks = (defined param("nolinks") && param("nolinks")) || $Format{$format}->{'nolinks'};
my $cookie = cookie({-name=>"query",
-value=>url(-absolute => 1, -query=>1)});
# Make various sorting URLs
if ( $sortorder ) {
param("sortorder", 0);
} else {
param("sortorder", 1);
}
param("sort", "id-n");
$sorturl{'id'} = url(-absolute => 1, -query=>1);
param("sort", "name");
$sorturl{'name'} = url(-absolute => 1, -query=>1);
param("sort", "status");
$sorturl{'status'} = url(-absolute => 1, -query=>1);
param("sort", "comments-n");
$sorturl{'comments'} = url(-absolute => 1, -query=>1);
param("sort", "documents-n");
$sorturl{'documents'} = url(-absolute => 1, -query=>1);
param("sort", "rating_avg-n");
$sorturl{'ratings'} = url(-absolute => 1, -query=>1);
param("sort", "action_id.precedence-n");
$sorturl{'action_id'} = url(-absolute => 1, -query=>1);
param("sort", "owner_id.name");
$sorturl{'owner'} = url(-absolute => 1, -query=>1);
param("sort", "opening_id.description");
$sorturl{'position'} = url(-absolute => 1, -query=>1);
param("sort", "age-n");
$sorturl{'age'} = url(-absolute => 1, -query=>1);
param("sort", "referrer");
$sorturl{'referrer'} = url(-absolute => 1, -query=>1);
if ( $param_sort ) {
param("sort", $url_sort);
} else {
Delete("sort");
}
ConnectToDatabase();
print header({-cookie=>"$cookie"});;
print doHeading({-title=>"Query Candidates Results"});
my $expand_action = url(-absolute => 1, -query=>1);
Delete("sort","sortorder", "groupby");
param("groupby","action");
my $groupby_action = url(-absolute => 1, -query=>1);
param("groupby", "status");
my $groupby_status = url(-absolute => 1, -query=>1);
Delete("groupby");
my $groupby_none = url(-absolute => 1, -query=>1);
if ( $param_sort ) {
param("sort", $param_sort);
} else {
Delete("sort");
}
if ( $param_groupby ) {
param("groupby", $param_groupby);
} else {
Delete("groupby");
}
print p("Legend:",
ul(
li(b("Rating:"), i(" number of your ratings:")," / ",i(" total number of ratings")," ",i("average overall rating")),
li(b("Coms:"), i(" number of your comments"), " / ", i("total number of comments")),
li(b("info:"), i(" whether we have contact info")),
)
);
print p("Note: sorting by columns will turn off grouping, for now.");
print start_p;
print
a({-href=>$groupby_action},"Group by action"), " | ",
a({-href=>$groupby_status},"Group by status"), " | ",
a({-href=>$groupby_none}, "Group by none") , " … ";
if ( $expand ) {
Delete("expand");
print a({-href=>url(-absolute => 1, -query=>1)}, "Unexpand");
} else {
Delete("expand");
param("expand", 1);
print a({-href=>url(-absolute => 1, -query=>1)}, "Expand");
}
print end_p;
my ($query, $hashes) = Query::makeQuery({ });
##
## XXX: if include_cc is selected, also get candidates who have the owner_id in the CC table
##
if ( param("include_cc") ) {
} else {
}
##
## Collects the results of the query and look for plug-in external calls
##
my @results = Query::extendedResults($query, $hashes);
# print Utility::ObjDump(\@results);
##
## After the results have been gathered, make a pass over the table format description and fill in any dynamic
## entries as needed (unimplemented)
##
foreach $r ( @results ) {
# If there are any callbacks on columns, process them now
foreach my $c ( @{$Format{$format}->{'columns'}} ) {
if ( exists $$c{'value'} ) {
SW1: {
# check for an external call
ref $$c{'value'} eq 'CODE' and do {
## CODE values result in calling the procedure with the candidate record
## as the argument.
$r->{$$c{'field'}} = &{$$c{'value'}}($r);
last SW1;
};
$r->{$$c{'field'}} = $$c{'value'};
};
}
}
}
if ( $sort ) {
if ( $sort =~ /-n$/ ) {
$sort =~ s/-n$//;
if ( $sortorder ) {
@results = sort {
defined $a && defined $a->{$sort} ?
( defined $b && defined $b->{$sort} ?
$b->{$sort} <=> $a->{$sort} : -1 ) :
( defined $b ? 1 : 0 ) } @results;
} else {
@results = sort {
defined $a && defined $a->{$sort} ?
( defined $b && defined $b->{$sort} ?
$a->{$sort} <=> $b->{$sort} : -1 )
: ( defined $b ? 1 : 0 ) } @results;
}
} else {
if ( $sortorder ) {
@results = sort {$b->{$sort} cmp $a->{$sort} } @results;
} else {
@results = sort {$a->{$sort} cmp $b->{$sort} } @results;
}
}
}
my $row = 0;
my $color;
my $lastsection = "impossible";
foreach $r ( @results ) {
my $doheading = 0;
if ( $groupby && $groupby ne "none" ) {
my $thissection;
if ( $groupby eq 'action' ) {
# WOLF FENCE
$thissection = (!defined $r->{'action_id'} || !$r->{'action_id'} ? 0 : $r->{'action_id'} );
if ( $lastsection ne $thissection ) {
print end_table, br;
print table({-border=>"0", -cellspacing=>"6", -cellpadding=>"4", -width=>"100%"},
Tr(
td({-bgcolor=>"#ffffff", -valign=>"bottom"},
h2(
("Next Action: ", $r->{'action_id.action'} ? $r->{'action_id.action'} : "none specified"),
))));
$lastsection = $thissection;
$doheading = 1;
$row = 0;
}
} elsif ( $groupby eq "status" ) {
$thissection = (!defined $r->{'status'} || !$r->{'status'} ? 0 : $r->{'status'} );
if ( $lastsection ne $thissection ) {
print end_table, br;
print table({-border=>"0", -cellspacing=>"6", -cellpadding=>"4", -width=>"100%"},
Tr(
td({-bgcolor=>"#ffffff", -valign=>"bottom"},
font({-size=>"4"},
("Status: ", $r->{'status'} ? $r->{'status'} : "UNDEFINED"),
))));
$lastsection = $thissection;
$doheading = 1;
$row = 0;
}
}
} else {
if ( $lastsection eq "impossible" ) {
$doheading = 1;
$lastsection = "x";
}
}
if ( $doheading ) {
print start_table({-width=>"100%", -cellspacing=>"0", -cellpadding=>"2"});
print start_Tr;
foreach my $c ( @{$Format{$format}->{'columns'}} ) {
my $str = b($c->{'heading'});
if ( !$nolinks ) {
if ( exists $$c{'url'} ) {
$str = a({-href=>$sorturl{$$c{'url'}}}, $str);
}
}
if ( exists $$c{'align'} ) {
$str = td({-align=>$$c{'align'}}, $str);
} else {
$str = td($str);
}
print "$str\n";
}
print end_Tr;
}
if ( $row%2 ) {
$color = "#ffffff";
} else {
$color = "#ddffdd";
}
$row++;
foreach my $c ( @{$Format{$format}->{'columns'}} ) {
my %colargs = ( -bgcolor=>$color, -valign=>"top" );
if ( exists $$c{'align'} ) {
$colargs{-align} = $$c{'align'};
}
if ( exists $$c{'nowrap'} ) {
$colargs{-nowrap} = $$c{'nowrap'}
}
my $str = "";
if ( exists $$c{'type'} ) {
SW: {
$$c{'type'} eq "YN" and do {
$str .= ($$c{'field'} && $$r{$$c{'field'}} ? "Y" : "N");
last SW;
};
};
} elsif ( exists $$c{'format'} ) {
if ( $$c{'field'} && $$r{$$c{'field'}} ) {
$str .= sprintf($$c{'format'}, $$r{$$c{'field'}});
} else {
$str .= "\ ";
}
} else {
if ( $$c{'field'} && $$r{$$c{'field'}} ) {
$str .= $$r{$$c{'field'}};
}
}
if ( !$nolinks && exists $$c{'link'} ) {
my $linkurl = &{$$c{'link'}}($$r{'id'});
$str = a({-href=>$linkurl}, $$r{$$c{'field'}});
if ( exists $$c{'warpable'} ) {
$lastURL = $linkurl;
}
}
if ( $expand && $c->{'expand'} ) {
$str .= br;
## Assumes that the hash $r->{$c->{'expand'}} is user_id => count
foreach $uid ( keys %{$r->{$c->{'expand'}}} ) {
$str .= "$r->{$c->{'expand'}}->{$uid}: " . User::getName($uid) . br;
}
}
print td(\%colargs, $str? $str : " "), "\n";
}
print end_Tr;
}
print end_table;
##
## If the "long" format was selected, then generate the long report on each candidate as well
##
if ( $format eq "long" ) {
foreach $r ( @results ) {
print hr, "\n";
my $candidate = Candidate::getRecord($r->{'id'});
## TODO: Make this heading a link to the detail page
print h2(Candidate::candidateLink({
-id=>$r->{'id'},
-target=>"_blank"
}));
print doStaticValues({
-record => $candidate,
-table => \%::CandidateTable,
-skipempty => 1,
});
print h3("Ratings");
print Candidate::formatRatings($r->{'id'});
print h3("Schedules"), "\n";
my @schedules = getRecordsMatch({
-table=>\%::InterviewTable,
-column=>"candidate_id",
-value=>$r->{'id'},
});
if ( scalar @schedules == 0 ) {
print p("None.");
} else {
print start_table({-cellpadding=>"4"});
print Tr(
td(b("When")),
td(b("Status")),
td(b("Who")),
td(b("Description")),
);
foreach my $s ( @schedules ) {
print start_Tr, "\n";
print td({-valign=>"top"}, $s->{'date'}), "\n";
print td({-valign=>"top"}, $s->{'status'}), "\n";
print start_td({-valign=>"top"}), "\n";
my $interviewers = Schedule::getInterviewers($s->{'id'});
my $lines_printed = 0;
foreach my $interviewer_name ( keys %$interviewers ) {
$lines_printed++ && print br;
print User::getName($interviewer_name), "\n";
}
print end_td, "\n";
print td({-valign=>"top"}, $s->{'purpose'}), "\n";
print end_Tr, "\n";
}
print end_table;
}
print h3("Comments");
my @comments = getRecordsMatch({
-table=>\%::CommentTable,
-column=>"candidate_id",
-value=>$r->{'id'},
});
foreach my $c ( @comments ) {
my $username = User::getName($c->{'user_id'});
print h4("By $username on $c->{'creation'}");
print p(Utility::cvtTextarea($c->{'comment'}));
}
}
}
##
## If there was only one result, then warp off to the last warpable URL that was seen in
## the table.
if ( scalar(@results) == 1 && $lastURL ) {
print script("document.location = '$lastURL'");
}
print p(scalar(@results) . " result" . (scalar(@results)!=1?"s":"") .
(!isAdmin() ? " (others may be hidden)" : "") . ".");
print Footer({-url=>"self_self_url"});
print end_html, "\n";
}