Subversion Repositories VORC

Rev

Rev 56 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 - 1
#!/usr/bin/perl
2
 
56 bgadell 3
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
4
my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
5
close STDERR;
6
open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
7
#warn "Redirecting errors to ${error_log_path}vorc_error.log";
8
 
7 - 9
use strict;
8 - 10
use cPanelUserConfig;
7 - 11
use RollerCon;
12
use tableViewer;
13
use CGI qw/param cookie header start_html url/;
14
use HTML::Tiny;
15
my $h = HTML::Tiny->new( mode => 'html' );
16
 
17
my $cookie_string = authenticate(2) || die;
18
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
19
my $user = getUser($EML);
20
$user->{department} = convertDepartments ($user->{department});
21
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
22
 
23
print header (-cookie=>$RCAUTH_cookie);
24
 
25
#foreach (sort keys %ENV) {
26
#	print "$_: $ENV{$_}\n<br>";
27
#}
28
my $change = param ('modtime') // "pick";
29
my $RCid   = param ('RCid');
30
my $shiftid     = param ('shiftid');
31
my $department = getShiftDepartment ($shiftid);
32
 
33
print start_html (-title => "vORC Modify Shift Time", -style => {'src' => "/style.css"}), $h->open ("body");
34
 
35
if ($user->{department}->{$department} < 2 or $LVL < 5) {
36
	print $h->div ({ class=>"error" }, "ERROR: You're not allowed to modify this shift's time.");
37
  print $h->close ("body"), $h->close ("html");
38
  die;
39
} elsif (!$shiftid or !$RCid) {
40
	print $h->div ({ class=>"error" }, "ERROR: Missing required fields.");
41
  print $h->close ("body"), $h->close ("html");
42
  die;
43
} elsif ($RCid eq $user->{RCid} and ($user->{department}->{$department} < 3 or $LVL < 5)) {
44
	print $h->div ({ class=>"error" }, "ERROR: Leads aren't allowed to modify their own shift's time.");
45
  print $h->close ("body"), $h->close ("html");
46
  die;
47
}
48
 
49
if ($change eq "pick") {
50
	use WebDB;
153 - 51
	my $dbh = WebDB::connect ();
7 - 52
 
53
	my ($current, $shiftlength) = $dbh->selectrow_array ("select mod_time, volhours from v_shift where RCid = ? and id = ?", undef, $RCid, $shiftid);
54
	$shiftlength -= $current;
55
 
56
	my $options;
57
	print $h->p ("Modifying time for Shift ($shiftid):");
58
	print $h->p ({ class=>"hint" }, "Add or Remove volunteer time earned if someone stays late or leaves early.");
59
  print $h->form ({ action=>url }, [
60
    $h->input ({ type=>"hidden", name=>"shiftid", value=>$shiftid }),
61
    $h->input ({ type=>"hidden", name=>"RCid", value=>$RCid }),
62
#    $h->p ("Modify Time for Shift ($RCid):"),
63
    $h->input ({ name=>"modtime", type=>"number", value=>$current, step=>.25, min=>-$shiftlength, id=>"pickname" }),
64
    $h->input ({ type=>"submit", value=>"Save", onClick=>"if (document.getElementById('pickname').selectedIndex === 0) { return false; }" }),
65
    $h->input ({ type=>"reset", value=>"Cancel", onClick=>"window.close();" })
66
  ]);
67
 
68
} else {
69
	print $h->p ("Modifying Shift Time...");
70
 
71
    my $target = getUserDerbyName ($RCid);
72
    print $h->p ("So, <b>$user->{derby_name}</b>, you'd like to add/remove time from a shift for <b>$target</b>: <b>$RCid</b>...");
73
 
74
	my $change_err = modShiftTime ($shiftid, $RCid, $change);
75
 
76
	print<<tail;
77
	<SCRIPT language="JavaScript">
78
	<!--
79
			function sleep(milliseconds) {
80
			  var start = new Date().getTime();
81
			  for (var i = 0; i < 1e7; i++) {
82
			    if ((new Date().getTime() - start) > milliseconds){
83
			      break;
84
			    }
85
			  }
86
			}
87
 
88
			function reloadParent() {
89
	      window.opener.document.Req.submit();
90
	      sleep(5000);
91
	      //window.close();
92
			}
93
 
94
			reloadParent();
95
	//-->
96
	</SCRIPT>
97
 
98
	</body></html>
99
 
100
tail
101
  print $h->close ("body"), $h->close ("html");
102
}