Subversion Repositories ORC

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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