Subversion Repositories VORC

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
252 - 1
#!/usr/bin/perl
2
 
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
 
9
use strict;
10
use cPanelUserConfig;
11
use WebDB;
12
use HTML::Tiny;
13
use RollerCon;
14
use CGI qw/param header start_html url url_param/;
15
my $h = HTML::Tiny->new( mode => 'html' );
16
 
17
my %F;
18
 
19
my $cookie_string = authenticate (RollerCon::USER) || die;
20
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
21
my $user = getUser ($EML);
22
$user->{department} = convertDepartments $user->{department};
23
my $DepartmentNames = getDepartments ();
24
my $username = $user->{derby_name};
25
my $RCid = $user->{RCid};
26
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
27
my $YEAR = 1900 + (localtime)[5];
28
 
29
my $pageTitle = "View Seminar";
30
my $homeURL = "/schedule/";
31
my $DBTable = "seminar";
32
my %FIELDS = (
33
  id          => [qw(SeminarID        5    auto        static )],
34
  name        => [qw(SeminarName     10    text        required )],
35
  coach       => [qw(Coach         15    placeholder    )],
36
  assistant   => [qw(Assistant     17    placeholder    )],
37
  date        => [qw(Date          20    date        required )],
38
  location    => [qw(Location      25    text        required )],
39
  start_time  => [qw(Start         30    time        required )],
40
  end_time    => [qw(End           35    time        required )],
41
  capacity    => [qw(Capacity      40    number      required )],
42
  note        => [qw(Notes         45    textarea       )],
43
);
44
 
45
 
46
my %fieldDisplayName = map  { $_ => $FIELDS{$_}->[0]   } keys %FIELDS;
47
my %fieldType        = map  { $_ => $FIELDS{$_}->[2]   } keys %FIELDS;
48
my @requiredFields   = sort fieldOrder grep { defined $FIELDS{$_}->[3] } keys %FIELDS;
49
my @DBFields   = sort fieldOrder grep { $fieldType{$_} =~ /^(text|select|number|switch|date|time|auto)/ } keys %FIELDS;
50
my @ROFields   = sort fieldOrder grep { $fieldType{$_} =~ /^(readonly)/ } keys %FIELDS;
51
my $primary = $DBFields[0];
52
 
53
sub fieldOrder {
54
  $FIELDS{$a}->[1] <=> $FIELDS{$b}->[1];
55
}
56
 
57
sub saveForm {
58
  my $FTS = shift;
59
  my $context = shift // "";
60
 
61
  error ("ERROR: Only SysAdmins can change games.") unless $LVL >= RollerCon::ADMIN or ($context eq "Save Note" and $user->{department}->{MVP} >= RollerCon::LEAD);
62
 
63
  my $dbh = WebDB::connect ();
64
  if ($FTS->{$DBFields[0]} eq "NEW") {
65
    $dbh->do (
66
      "INSERT INTO $DBTable
67
      (name,date,location,start_time,end_time,capacity,note)
68
      VALUES(?,?,?,?,?,?,?)",
69
      undef,
70
      $FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{start_time}, $FTS->{end_time}, $FTS->{capacity}, $FTS->{note}
71
    );
72
    ($FTS->{id}) = $dbh-> selectrow_array ("select max(id) from $DBTable where name = ? and date = ? and location = ? and start_time = ? and end_time = ?", undef, $FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{start_time}, $FTS->{end_time});
73
    logit ($RCid, "$username created new seminar ($FTS->{id}, $FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{start_time}, $FTS->{end_time}, $FTS->{capacity})");
74
 
75
    # Coach and Asst Coach need to be added after the seminar is created so that we have the seminar id...
76
    if ($FTS->{coach}) { change_coach ("save", "coach", $FTS->{id}, $FTS->{coach}); }
77
    if ($FTS->{assistant}) { change_coach ("save", "assistant", $FTS->{id}, $FTS->{assistant}); }
78
 
79
  } elsif ($context eq "Save Note") {
80
    # We're just updating the Note...
81
    $dbh->do ("update seminar set note = ? where id = ?", undef, $FTS->{note}, $FTS->{id});
82
    logit ($RCid, "$username updated seminar ($FTS->{id}) with Note: $FTS->{note})");
83
  } else {
84
    # Update the Coach and Asst Coach volunteer shifts first (so that the original date, time, location still matches...)
85
    $dbh->do (
86
      "update shift set
87
	      start_time = ?,
88
        end_time = ?,
89
        date = ?,
90
        location = ?,
91
        note = ?
92
      where
93
	      dept = ? and
94
        date = (select date from seminar where id = ?) and
95
        location = (select location from seminar where id = ?) and
96
	      start_time = (select start_time from seminar where id = ?)",
97
	      undef,
98
	    $FTS->{start_time}, $FTS->{end_time}, $FTS->{date}, $FTS->{location}, $FTS->{name}, "COA", $FTS->{id}, $FTS->{id}, $FTS->{id}
99
    );
100
    # Now update the seminar.
101
    $dbh->do (
102
      "UPDATE $DBTable
103
      SET name=?, date=?, location=?, start_time=?, end_time=?, capacity=?, note=?
104
      WHERE id = ?",
105
      undef,
106
      $FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{start_time}, $FTS->{end_time}, $FTS->{capacity}, $FTS->{note}, $FTS->{id}
107
    );
108
    logit ($RCid, "$username updated seminar ($FTS->{id}, $FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{start_time}, $FTS->{end_time}, $FTS->{capacity})");
109
  }
110
 
111
  $dbh->disconnect ();   # stored into database successfully.
112
  return $FTS->{id};
113
}
114
 
115
sub delete_item {
116
  error ("ERROR: Only SysAdmins can change games.") unless $LVL >= RollerCon::ADMIN;
117
 
118
  my $X = shift;
119
  my $dbh = WebDB::connect ();
120
 
121
  # Delete the Coach and Asst Coach first while we can still do a subselect with the seminar id...
122
  $dbh->do ("delete from shift
123
             where
124
               dept = ? and
125
               date = (select date from seminar where id = ?) and
126
               location = (select location from seminar where id = ?) and
127
               start_time = (select start_time from seminar where id = ?)",
128
             undef,
129
             "COA", $X->{$primary}, $X->{$primary}, $X->{$primary}
130
           );
131
  $dbh->do ("delete from $DBTable where $primary = ?", undef, $X->{$primary});
132
  ## If we're deleting a seminar, we need to also delete all of the sign-ups
133
  ##    TBD: Maybe email all of the attendees that their seminar is being deleted first?
134
  $dbh->do ("delete from assignment where Gid = ? and role like ?", undef, $X->{$primary}, "CLA".'%');
135
 
136
  $dbh->disconnect ();
137
  logit ($RCid, "$username deleted Seminar ($X->{$primary})");
138
  print "Seminar Deleted: $X->{$primary}", $h->br;
139
  print &formField ("Cancel", "Back", "POSTSAVE");
140
}
141
 
142
 
143
sub select_coach {
144
  my $selection = shift // "";
145
 
146
  return $h->select ({ name=>"coach" }, [ $h->option (""), fetchDerbyNameWithRCid ("COA", $selection) ]);
147
};
148
 
149
sub select_assistant {
150
  my $selection = shift // "";
151
 
152
  return $h->select ({ name=>"assistant" }, [ $h->option (""), fetchDerbyNameWithRCid ("COA", $selection) ]);
153
};
154
 
155
sub change_coach {
156
  my $change = shift // "";
157
  my $role   = shift // "";
158
  my $seminar_id = shift // "";
159
  my $coach_id = shift // "";
160
 
161
  error ("SECURITY: You're not allowed to change the seminar coaches!") unless ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::MANAGER or $user->{department}->{VCI} >= RollerCon::MANAGER);
162
 
163
  my $dbh = WebDB::connect ();
164
 
165
  if ($change eq "delete") {
166
    my ($r1, $r2);
167
    if ($role eq "assistant") {
168
      $r1 = "Seminar Assistant (SA)";
169
      $r2 = "Seminar Assistant Coach";
170
    } else {
171
      $r1 = "Seminar Coach";
172
      $r2 = "Seminar Coach";
173
    }
174
    $dbh->do ("delete from shift where
175
                  assignee_id = ? and
176
                  dept = ? and
177
                  role in (?, ?) and
178
                  date = (select date from seminar where id = ?) and
179
                  start_time = (select start_time from seminar where id = ?) and
180
                  location = (select location from seminar where id = ?)", undef,
181
              $coach_id, "COA", $r1, $r2, $seminar_id, $seminar_id, $seminar_id);
182
  } elsif ($change eq "save") {
183
    my $r1 = ($role eq "assistant") ? "Seminar Assistant (SA)" : "Seminar Coach";
184
    $dbh->do ("insert into shift (dept, role, type, date, location, start_time, end_time, doubletime, note, assignee_id)
185
               select ?, ?, ?, date, location, start_time, end_time, 1, name, ? from seminar where id = ?", undef,
186
               "COA", $r1, "selected", $coach_id, $seminar_id);
187
  }
188
 
189
  logit ($RCid, "Seminar Coach Change: $change $role for seminar $seminar_id with RCid $coach_id");
190
 
191
  $dbh->disconnect ();
192
}
193
 
194
print header ( -cookie=> [ $RCAUTH_cookie ] ),
195
      start_html (-title => $pageTitle, -style => {'src' => "/style.css"} );
196
 
197
print $h->div ({ class => "accent pageheader" }, [
198
  $h->h1 ($pageTitle),
199
  $h->div ({ class=>"sp0" }, [
200
    $h->div ({ class=>"spLeft" }, [
201
    ]),
202
    $h->div ({ class=>"spRight" }, [
203
      $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
204
    ]),
205
  ]),
206
]);
207
 
208
my $coaching_change = param ("coachchange") // "";
209
if ($coaching_change =~ /^(save|delete)_/) {
210
  my ($change, $role, $seminar, $coach);
211
  $seminar = param ("id");
212
  ($change, $role) = split /_/, $coaching_change;
213
  if ($change eq "save") {
214
    $coach = param ($role);
215
  } elsif ($change eq "delete") {
216
    ($role, $coach) = split /:/, $role;
217
  }
218
  change_coach ($change, $role, $seminar, $coach);
219
}
220
 
221
my $choice = param ("choice") // "";
222
if ($choice =~ /^Save/) {
223
  process_form ($choice);
224
} elsif (defined (param ($primary) || url_param ($primary))) {
225
  my $thing = param ($primary); $thing //= url_param ($primary);
226
  if ($choice eq "Delete") {
227
    delete_item ({ $primary => $thing });
228
  } else {
229
    display_form ({ $primary => $thing }, $choice);
230
  }
231
} else {
232
  display_form (); # blank form
233
}
234
 
235
print $h->close ("html");
236
 
237
sub display_form  {
238
  my $R = shift;
239
  my $view = shift // "";
240
  my $actionbutton;
241
  my $coachRCid;
242
  my (@CoachRCids, @AsstCoachRCids);
243
 
244
  $view = "View" unless $LVL >= RollerCon::ADMIN or ($view eq "Add Note" and $user->{department}->{MVP} >= RollerCon::LEAD);
245
 
246
  if ($view eq "POSTSAVE" and $R->{$primary} eq "NEW") {
247
      print &formField ("Cancel", "Back", "POSTSAVE");
248
      return;
249
  }
250
 
251
  if ($R) {
252
    # we're dealing with an existing thing.  Get the current values out of the DB...
253
    my $dbh = WebDB::connect ();
254
 
255
    @F{@DBFields} = $dbh->selectrow_array (
256
                     "SELECT ". join (", ", @DBFields) ." FROM $DBTable WHERE $primary = ?",
257
                      undef, $R->{$primary});
258
 
259
    # Get the Coach and Assistant Coach shifts...
260
    my (@CoachShifts, @AsstCoachShifts);
261
    my $shifthand = $dbh->prepare ("select id from shift where dept = ? and role = ? and date = ? and start_time = ? and location = ?");
262
 
263
    $shifthand->execute ("COA", "Seminar Coach", $F{date}, $F{start_time}, $F{location});
264
    while (my ($seminarshiftid) = $shifthand->fetchrow_array ()) {
265
      push @CoachShifts, $seminarshiftid;
266
    }
267
 
268
    $shifthand->execute ("COA", "Assistant Seminar Coach", $F{date}, $F{start_time}, $F{location});
269
    while (my ($seminarshiftid) = $shifthand->fetchrow_array ()) {
270
      push @AsstCoachShifts, $seminarshiftid;
271
    }
272
    $shifthand->execute ("COA", "Seminar Assistant (SA)", $F{date}, $F{start_time}, $F{location});
273
    while (my ($seminarshiftid) = $shifthand->fetchrow_array ()) {
274
      push @AsstCoachShifts, $seminarshiftid;
275
    }
276
 
277
    $dbh->disconnect ();
278
 
279
    # did we find a record?
280
    error ("Cannot find a database entry for Seminar with id: '$R->{$primary}'") unless defined $F{$DBFields[0]};
281
 
282
    # If the DB returns a null value, HTML::Tiny doesn't like it, so make sure nulls are converted to empty strings.
283
    map { $F{$_} = "" unless $F{$_} } @DBFields;
284
 
285
    if ($view eq "Update") {
286
      # We'd like to update that thing, give the user a form...
287
      print $h->p ("Updating Seminar: $R->{$primary}...");
288
 
289
      foreach (@DBFields) {
290
        $F{$_} = formField ($_, $F{$_});
291
      }
292
      $F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0],   value=> $F{$DBFields[0]} });
293
 
294
      $actionbutton = formField ("choice", "Save");
295
      $actionbutton .= formField ("Cancel");
296
    } elsif ($view eq "Add Note") {
297
      # Leads may add a note to the seminar (to include an Asst Coach that doesn't have Coach access yet)
298
      print $h->p ("Add a Note to Seminar: $R->{$primary}...");
299
 
300
      $F{note} = formField ("note", $F{note});
301
      $F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0],   value=> $F{$DBFields[0]} });
302
 
303
      $actionbutton = formField ("choice", "Save Note");
304
      $actionbutton .= formField ("Cancel");
305
    } elsif ($view eq "Copy") {
306
      # We'd like to copy that thing, give the user a form...
307
      print $h->p ("Copying Seminar: $R->{$primary}...");
308
 
309
      foreach (@DBFields) {
310
        $F{$_} = formField ($_, $F{$_});
311
      }
312
      $F{$DBFields[0]} = "COPY".$h->input ({ type=>"hidden", name=>$DBFields[0], value=> "NEW" });
313
 
314
      $actionbutton = formField ("choice", "Save");
315
      $actionbutton .= formField ("Cancel");
316
    } else {
317
      # We're just looking at it...
318
      print $h->p ("Viewing Seminar: $R->{$primary}...");
319
 
320
      if ($ORCUSER->{MVPid}) {
321
        my $dbh = WebDB::connect ();
322
        ($F{available}) = $dbh->selectrow_array ("select available from v_seminar_new where id = ?", undef, $R->{id});
323
        $dbh->disconnect;
324
        $F{capacity} = $F{available} . " / " . modify_capacity (\%F);
325
      }
326
 
327
      $F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0], value=> $F{$DBFields[0]} });
328
 
329
      my $coachEditor = ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::MANAGER or $user->{department}->{VCI} >= RollerCon::MANAGER) ? 1 : 0;
330
      $coachRCid = $F{coach};
331
      $F{coach} = "";
332
      foreach (@CoachShifts) {
333
        my $sr = getShiftRef ($_);
334
        $F{coach} .= $h->a ({ href=>"/schedule/view_coach.pl?RCid=$sr->{assignee_id}" }, getUserDerbyName ($sr->{assignee_id}));
335
        $F{coach} .= '&nbsp;' . $h->button ({name => "coachchange",  value => "delete_coach:$sr->{assignee_id}"}, "Remove") if $coachEditor;
336
        $F{coach} .= $h->br;
337
        push @CoachRCids, $sr->{assignee_id};
338
      }
339
      if ($coachEditor) {
340
        my $context = param ("coachchange");
341
        if ($context eq "add_coach") {
342
          $F{coach} .= select_coach () . $h->button ({name => "coachchange",  value => "save_coach"}, "Save");
343
        } else {
344
          $F{coach} .= $h->button ({name => "coachchange",  value => "add_coach"}, "Add Coach");
345
        }
346
      }
347
 
348
      $F{assistant} = "";
349
      foreach (@AsstCoachShifts) {
350
        my $sr = getShiftRef ($_);
351
        $F{assistant} .= $h->a ({ href=>"/schedule/view_coach.pl?RCid=$sr->{assignee_id}" }, getUserDerbyName $sr->{assignee_id});
352
        $F{assistant} .= '&nbsp;' . $h->button ({name => "coachchange",  value => "delete_assistant:$sr->{assignee_id}"}, "Remove") if $coachEditor;
353
        $F{assistant} .= $h->br;
354
        push @AsstCoachRCids, $sr->{assignee_id};
355
      }
356
      if ($coachEditor) {
357
        my $context = param ("coachchange");
358
        if ($context eq "add_assistant") {
359
          $F{assistant} .= select_assistant () . $h->button ({name => "coachchange",  value => "save_assistant"}, "Save");
360
        } else {
361
          $F{assistant} .= $h->button ({name => "coachchange",  value => "add_assistant"}, "Add Assistant");
362
        }
363
      }
364
 
365
      $F{start_time} = convertTime $F{start_time};
366
      $F{end_time}   = convertTime $F{end_time};
367
 
368
      $actionbutton = formField ("choice", "Update") unless $LVL < RollerCon::ADMIN;
369
      $actionbutton .= formField ("choice", "Add Note") if $user->{department}->{MVP} >= RollerCon::LEAD;
370
      if ($view eq "POSTSAVE" or $choice eq "View") {
371
        $actionbutton .= formField ("Cancel", "Back", "POSTSAVE");
372
      } else {
373
        $actionbutton .= formField ("Cancel", "Back");
374
      }
375
    }
376
  } else {
377
    error ("No Game id provided.") unless $LVL >= RollerCon::ADMIN;
378
 
379
    print $h->p ("Adding a new Seminar...");
380
 
381
    foreach (@DBFields) {
382
      $F{$_} = formField ($_);
383
    }
384
    $F{$DBFields[0]} = "NEW".$h->input ({ type=>"hidden", name=>$DBFields[0], value=> "NEW" });
385
 
386
    $F{coach} = select_coach ();
387
    $F{assistant} = select_assistant ();
388
 
389
    $actionbutton = formField ("choice", "Save");
390
    $actionbutton .= formField ("Cancel");
391
  }
392
 
393
 
394
  print $h->open ("form", { action => url (), name=>"Req", method=>"POST" });
395
  print $h->div ({ class=>"sp0" },
396
    $h->div ({ class=>"rTable" }, [ map ({
397
      $h->div ({ class=>"rTableRow" }, [
398
        $h->div ({ class=>"rTableCell right top", style=>"font-size:unset;" }, "$fieldDisplayName{$_}: "),
399
        $h->div ({ class=>"rTableCell", style=>"font-size:unset;" }, $F{$_})
400
      ])
401
       } sort fieldOrder keys %FIELDS),
402
   ])
403
  );
404
 
405
  print $actionbutton;
406
  print $h->close ("form");
407
 
408
  print $h->p ($h->input ({ type=>"button", onClick=>"window.location.href='email_users.pl?type=seminar&ID=$R->{$primary}';", value=>"Email Users" })) unless $LVL < RollerCon::ADMIN;
409
 
410
  my $dbh = WebDB::connect ();
411
 
412
  my ($seminar_is_over) = $dbh->selectrow_array ("select 1 from v_seminar_new where $primary = ? and concat_ws(' ', date, end_time) < date_sub(now(), interval 2 hour)", undef, $R->{$primary});
413
 
414
  # View the list of people signed up for the seminar...
415
  if ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD) {
416
    my ($count) = $dbh->selectrow_array ("select count from v_seminar_new where $primary = ?", undef, $R->{$primary});
417
 
418
    if ($F{$DBFields[0]} !~ /^(NEW|COPY)/) {
419
      my @A = @{$dbh->selectall_arrayref ("select role, official.RCid, derby_name from v_seminar_signup_new join official on v_seminar_signup_new.RCid = official.RCid where $primary = ? order by cast(right(role, if(char_length(role) = 5, 1, 2)) as UNSIGNED) asc", undef, $R->{$primary})};
420
 
421
      my $seminarkey = join '|', "SEM", $F{date}, $F{start_time}, $F{location};
422
      my $adduserlink  = ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD) ? $h->a ({ style=>"color:unset;font-size:x-small;", onClick=>"window.open('make_shift_change.pl?change=lookup&RCid=$RCid&id=$seminarkey','Confirm Shift Change','resizable,height=260,width=370'); return false;" }, "[ADD USER]") : "";
423
 
424
      print $h->br, $h->br;
425
      print $h->div ({ class=>"index", style=>"max-width:610px" }, [ $h->p ({ class=>"heading" }, [ "Sign-ups:&nbsp;&nbsp;", $adduserlink ]),
426
        $h->ul ( [ map { $h->li ({ class=>"shaded", style=>"margin:4px;" },
427
          $h->div ({ class=>"lisp0" }, [
428
            $h->div ({ class=>"liLeft"  }, [ $$_[0], ":&nbsp;&nbsp;", $h->a ({ href=>"/schedule/view_user.pl?RCid=$$_[1]" }, $$_[2]) ]),
429
            $h->div ({ class=>"liRight" }, ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD) ? $h->a ({ style=>"font-size:small", onClick=>"if (confirm('Really? Delete $$_[2] from this seminar?')==true) { window.open('make_shift_change.pl?change=del&RCid=$$_[1]&id=$R->{$primary}&role=$$_[0]','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "[DROP]") : "")
430
          ])
431
        ) } @A ])
432
      ]);
433
    }
434
  }
435
 
436
  # View the survey results...
437
  use tableViewer qw/inArray/;
438
  if (($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD or inArray ($ORCUSER->{RCid}, \@CoachRCids)) and $seminar_is_over) {
439
    my ($response_count) = $dbh->selectrow_array ("select count(distinct(RCid)) from v_seminar_survey_answer where seminarid = ?", undef, $R->{$primary});
440
    my $exclude_private = ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD) ? "" : "and private = 0";
441
 
442
    my @RESPONSES = @{$dbh->selectall_arrayref ("select qorder, type, question, average, qid from v_seminar_survey_results where seminarid = ? $exclude_private order by qorder", undef, $R->{$primary})};
443
 
444
    print $h->br, $h->br;
445
    print $h->div ({ class=>"index", style=>"max-width:610px" }, [ $h->p ({ class=>"heading" }, [ "Survey Results:&nbsp;&nbsp;", $response_count." Response".(($response_count > 1) ? "s" : "") ]),
446
      $h->ul ( [ map { $h->li ({ class=>"shaded", style=>"margin:4px;" },
447
        $h->div ({ class=>"lisp0" }, [
448
          $h->div ({ class=>"liLeft"  }, [ $$_[0], ":&nbsp;", $$_[2] ]),
449
          $h->div ({ class=>"liRight" }, [ $$_[1] eq "text" ?
450
            $h->a ({ href=>"view_seminar_survey_comments.pl?seminarid=$R->{$primary}&qid=$$_[4]" }, [ $$_[3], (($$_[3] == 1) ? " comment" : " comments") ]) :
451
            $$_[3] ])
452
        ])
453
      ) } @RESPONSES ])
454
    ]);
455
  }
456
  $dbh->disconnect;
457
}
458
 
459
sub process_form  {
460
  my $context = shift // "";
461
  error ("ERROR: Only SysAdmins can change games.") unless $LVL >= RollerCon::ADMIN or ($context eq "Save Note" and $user->{department}->{MVP} >= RollerCon::LEAD);
462
 
463
  my %FORM;
464
  foreach (keys %FIELDS) {
465
    if ($fieldType{$_} =~ /^text/) {
466
      $FORM{$_} = WebDB::trim param ($_) // "";
467
    } else {
468
      $FORM{$_} = param ($_) // "";
469
    }
470
  }
471
 
472
     # check for required fields
473
  my @errors = ();
474
  foreach (@requiredFields) {
475
    push @errors, "$fieldDisplayName{$_} is missing." if ($FORM{$_} eq "" and $context ne "Save Note");
476
  }
477
  push @errors, "Capacity should be a whole number." unless ($FORM{capacity} =~ /^\d+$/ or $context eq "Save Note");
478
 
479
  if (@errors)   {
480
    print $h->div ({ class=>"error" }, [
481
      $h->p ("The following errors occurred:"),
482
      $h->ul ($h->li (@errors)),
483
      $h->p ("Please click your Browser's Back button to\n"
484
           . "return to the previous page and correct the problem.")
485
    ]);
486
    return;
487
  }  # Form was okay.
488
 
489
  $FORM{id} = saveForm (\%FORM, $context);
490
 
491
  print $h->p ({ class=>"success" }, "Seminar successfully saved.");
492
 
493
  display_form ({ $primary=>$FORM{id} }, "POSTSAVE");
494
}
495
 
496
sub modify_capacity {
497
  my $t = shift;
498
 
499
  my $seminarid = $t->{id};
500
  $seminarid =~ s/^(\d+).*/$1/;
501
 
502
  use DateTime;
503
  my $now = DateTime->now (time_zone => 'America/Los_Angeles');
504
  my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
505
  my $cutoff = DateTime->new(
506
        year => $yyyy,
507
        month => $mm,
508
        day => $dd,
509
        hour => 5,
510
        minute => 0,
511
        second => 0,
512
        time_zone => 'America/Los_Angeles'
513
  );
514
 
515
  return $t->{capacity} . " | CLOSED" unless $now < $cutoff;
516
 
517
  my $seminarkey = join '|', "SEM", $t->{date}, $t->{start_time}, $t->{location};
518
 
519
  my $dbh = WebDB::connect;
520
  ($t->{signedup}) = $dbh->selectrow_array ("select role from v_seminar_signup_new where RCid = ? and id = ?", undef, $ORCUSER->{RCid}, $seminarid );
521
  $dbh->disconnect;
522
  my $droplink = $h->button ({ onClick=>"if (confirm('Really? You want to drop this seminar?')==true) { window.open('make_shift_change.pl?change=del&RCid=$ORCUSER->{RCid}&id=$seminarid&role=$t->{signedup}','Confirm Change','resizable,height=260,width=370'); return false; }" }, "DROP");
523
  if (!$t->{available}) {
524
    my $full = " | FULL";
525
    $full .= '&nbsp;'.$droplink unless !$t->{signedup};
526
    return $t->{capacity} . $full;
527
  }
528
 
529
#  $t->{capacity} .= " | Open";
530
  $t->{capacity} .= '&nbsp;'.$droplink unless !$t->{signedup};
531
  if (findConflict ($ORCUSER->{RCid}, $seminarid, "seminar")) {
532
    $t->{capacity} .= " | *schedule conflict*" unless $t->{signedup};
533
  } elsif (signUpEligible ($ORCUSER, $t, "seminar")) {
534
    # SIGN UP
535
    $t->{capacity} .= '&nbsp;'.$h->button ({ onClick=>"event.stopPropagation(); window.open('make_shift_change.pl?change=add&RCid=$ORCUSER->{RCid}&id=$seminarkey','Confirm Seminar Change','resizable,height=260,width=370'); return false;" }, "SIGN UP");
536
  }
537
 
538
  return $t->{capacity};
539
}
540
 
541
sub error {
542
  my $msg = shift;
543
  print $h->p ({ class=>"error" }, "Error: $msg");
544
  print $h->close("html");
545
  exit (0);
546
}
547
 
548
sub formField {
549
  my $name  = shift;
550
  my $value = shift // '';
551
  my $context = shift // '';
552
  my $type = $fieldType{$name} // "button";
553
 
554
  if ($type eq "button") {
555
    if ($name eq "Cancel") {
556
      if ($context eq "POSTSAVE") {
557
        return $h->input ({ type=>"button", value => $value ne '' ? $value : "Cancel" , onClick=>"window.location.href = \"seminars.pl\"; return false;" });
558
      } else {
559
        return $h->input ({ type=>"button", value => $value ne '' ? $value : "Cancel" , onClick=>"history.back(); return false;" });
560
      }
561
    } else {
562
      return $h->input ({ type=>"submit", value => $value, name=>$name })
563
    }
564
 
565
  } elsif ($type eq "textarea") {
566
    return $h->tag ("textarea", {
567
      name => $name,
568
      override => 1,
569
      cols => 30,
570
      rows => 4
571
    }, $value);
572
 
573
  } elsif ($type eq "select") {
574
    no strict;
575
    return &{"select_".$name} ($value);
576
  } elsif ($type eq "auto") {
577
    return $name eq "assignee_id" ? getUserDerbyName ($value) : $value;
578
  } elsif ($type eq "time") {
579
    return $h->input ({
580
      name => $name,
581
      type => $type,
582
      value => $value,
583
      step => 900,
584
      required => [],
585
      override => 1,
586
      size => 30
587
    });
588
  } elsif ($type eq "number") {
589
    return $h->input ({ name=>$name, type=>"number", value=>$value, step=>1 });
590
  } elsif ($type eq "switch") {
591
    if ($value) {
592
      return $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>$name, value=>1, checked=>[] }), $h->span ({ class=>"slider round" })]);
593
    } else {
594
      return $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>$name, value=>1 }), $h->span ({ class=>"slider round" })]);
595
    }
596
  } elsif ($type eq "placeholder") {
597
  } else {
598
    use tableViewer qw/inArray/;
599
    if (inArray ($name, \@requiredFields)) {
600
      return $h->input ({
601
        name => $name,
602
        type => $type,
603
        value => $value,
604
        required => [],
605
        override => 1,
606
        size => 30
607
      });
608
    } else {
609
      return $h->input ({
610
        name => $name,
611
        type => $type,
612
        value => $value,
613
        override => 1,
614
        size => 30
615
      });
616
    }
617
  }
618
}
619