Subversion Repositories VORC

Rev

Rev 204 | Rev 215 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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