Subversion Repositories ORC

Rev

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

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