version 1.252, 2005/09/28 13:29:17
|
version 1.253, 2005/09/28 23:19:25
|
Line 2751 ENDMAINFORMHEAD
|
Line 2751 ENDMAINFORMHEAD
|
} |
} |
### Set instructor defined metadata |
### Set instructor defined metadata |
sub output_row { |
sub output_row { |
my ($field_name) = @_; |
my ($r, $field_name) = @_; |
my $output; |
my $output; |
my $meta_hash_ref=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name}; |
my $active=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.active'}; |
my $values=$$meta_hash_ref{'values'}; |
my $onlyone=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.onlyone'}; |
|
my $stuadd=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.stuadd'}; |
|
my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'}; |
my $checked; |
my $checked; |
unless (defined($$meta_hash_ref{'active'})) { |
unless (defined($active)) { |
$$meta_hash_ref{'active'} = 'no'; |
$active = 'no'; |
$$meta_hash_ref{'stu_add_values'} = 'yes'; |
$stuadd = 'yes'; |
$$meta_hash_ref{'values'} = 'Type a list of values separated by commas.'; |
$values = 'Type a list of values separated by commas.'; |
$$meta_hash_ref{'stu_pick_many'} = 'yes'; |
$onlyone = 'no'; |
} |
} |
$output.='<tr><td><strong>'.$field_name.'</strong></td>'; |
$output.='<tr><td><strong>'.$field_name.'</strong></td>'; |
$output.='<td><input name="'.$field_name.'_values" type="text" value="'.$$meta_hash_ref{'values'}.'" /></td>'; |
$output.='<td><input name="'.$field_name.'_values" type="text" value="'.$values.'" /></td>'; |
if ($$meta_hash_ref{'stu_add_values'}eq'yes') { |
if ($onlyone eq 'no') { |
$checked = ' CHECKED '; |
$checked = ' CHECKED '; |
} else { |
} else { |
$checked = ' '; |
$checked = ' '; |
} |
} |
$output.='<td><center><input type="checkbox" name="'.$field_name.'_onlyone"" value="one"'.$checked.' /></center></td>'; |
$output.='<td><center><input type="checkbox" name="'.$field_name.'_onlyone"" value="yes"'.$checked.' /></center></td>'; |
if ($$meta_hash_ref{'stu_pick_many'}eq'yes') { |
if ($stuadd eq 'yes') { |
$checked = ' CHECKED '; |
$checked = ' CHECKED '; |
} else { |
} else { |
$checked = ' '; |
$checked = ' '; |
} |
} |
$output.='<td><input type="checkbox" name="'.$field_name.'_stuadd" value="one"'.$checked.' /></td>'; |
$output.='<td><input type="checkbox" name="'.$field_name.'_stuadd" value="yes"'.$checked.' /></td>'; |
$output.='</tr>'; |
$output.='</tr>'; |
|
|
return ($output); |
return ($output); |
} |
} |
sub setinstmeta { |
sub setinstmeta { |
Line 2797 sub setinstmeta {
|
Line 2798 sub setinstmeta {
|
my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $key_base = $env{'course.'.$env{'request.course.id'}.'.metadata.'}; |
my $key_base = $env{'course.'.$env{'request.course.id'}.'.metadata.'}; |
my $save_field = ''; |
my $save_field = ''; |
my %meta_hash; |
my $stuadd; |
|
my $onlyone; |
|
my $active; |
if ($env{'form.instmeta'}) { |
if ($env{'form.instmeta'}) { |
foreach my $field (sort %env) { |
foreach my $field (sort %env) { |
if ($field=~m/^form.(.+)_(.+)$/) { |
if ($field=~m/^form.(.+)_(.+)$/) { |
my $meta_field = $1; |
my $meta_field = $1; |
my $meta_key = $2; |
my $meta_key = $2; |
if ($save_field eq $meta_field) { |
if ($save_field ne $meta_field) { |
%meta_hash = {$meta_key=>[$env{$field}]}; |
|
} else { |
|
if ($save_field ne '') { |
|
%meta_hash = {active=>'yes'}; |
|
my $value = \%meta_hash; |
|
my $name = $save_field; |
|
$r->print('Saving '.$name.' meta<br />'); |
|
$put_result = &Apache::lonnet::put('environment', |
|
{$name=>$value},$dom,$crs); |
|
} |
|
$save_field = $meta_field; |
$save_field = $meta_field; |
%meta_hash = {$meta_key=>[$env{$field}]}; |
if ($env{'form.'.$meta_field.'_stuadd'}) { |
|
$stuadd='yes'; |
|
} else { |
|
$stuadd='no'; |
|
} |
|
if ($env{'form.'.$meta_field.'_onlyone'}) { |
|
$onlyone='no'; |
|
} else { |
|
$onlyone='yes'; |
|
} |
|
$active='yes'; |
|
my $name = 'metadata.'.$save_field; |
|
$put_result = &Apache::lonnet::put('environment', |
|
{'metadata.'.$meta_field.'.stuadd'=>$stuadd, |
|
'metadata.'.$meta_field.'.onlyone'=>$onlyone, |
|
'metadata.'.$meta_field.'.active'=>$active, |
|
'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'}, |
|
},$dom,$crs); |
} |
} |
} |
} |
|
|
|
|
} |
} |
%meta_hash = {active=>'yes'}; |
|
my $value = \%meta_hash; |
|
my $name = $save_field; |
|
$r->print('Saving '.$name.' meta<br />'); |
|
$put_result = &Apache::lonnet::put('environment', |
|
{$name=>$value},$dom,$crs); |
|
} |
} |
foreach my $field (%env) { |
foreach my $field (%env) { |
# start by looking for populated fields |
# start by looking for populated fields |
if ($field=~m/type(\d+)/) { |
if ($field=~m/type(\d+)/) { |
my $name; |
my $name; |
my $value; |
my $value; |
$put_result = &Apache::lonnet::put('environment', |
# $put_result = &Apache::lonnet::put('environment', |
{$name=>$value},$dom,$crs); |
# {$name=>$value},$dom,$crs); |
$put_result = &Apache::lonnet::put('environment', |
# $put_result = &Apache::lonnet::put('environment', |
{$name=>$value},$dom,$crs); |
# {$name=>$value},$dom,$crs); |
} |
} |
if ($field=~m/newfield/) { |
if ($field=~m/newfield/) { |
my $name = 'metadata.'.$env{'form.titlenew'}; |
my $name = 'metadata.'.$env{'form.titlenew'}; |
Line 2845 sub setinstmeta {
|
Line 2848 sub setinstmeta {
|
allow_type=>'no'}; |
allow_type=>'no'}; |
|
|
my $value = \%meta_hash; |
my $value = \%meta_hash; |
$put_result = &Apache::lonnet::put('environment', |
# $put_result = &Apache::lonnet::put('environment', |
{$name=>$value},$dom,$crs); |
# {$name=>$value},$dom,$crs); |
} |
} |
} |
} |
&Apache::lonnet::coursedescription($env{'request.course.id'}); |
&Apache::lonnet::coursedescription($env{'request.course.id'}); |
$output.= &output_row("Title"); |
$output.= &output_row($r, "Title"); |
$output.= &output_row("Subject"); |
$output.= &output_row($r, "Subject"); |
$output.= &output_row("Keywords"); |
$output.= &output_row($r, "Keywords"); |
# foreach my $key (sort keys %env) { |
|
# if ($key=~m/^course\.$env{'request.course.id'}\.metadata\.(.+)$/) { |
|
# my $meta_data_item = $1; |
|
# my $meta_hash=$env{$key}; |
|
# # keys are 'values', stu_pick_many, stu_add_values, active |
|
# |
|
# $output.='<tr><td>'.$meta_data_item.'</td>'; |
|
# $output.='<td>Select one: <input type="checkbox" name="" value="one" /><br />'; |
|
# $output.='Select many: <input type="checkbox" name="type" value="many" /></td>'; |
|
# $output.='<td><input name="values" type="text" value="$env{$key_base.$item_num.'.'" /></td></tr>'; |
|
# } |
|
# } |
|
# $output.='<tr><td><i>Create new instructor metadata item</i><br />'; |
|
# $output.='<input type="text" name="titlenew" /></td>'; |
|
# $output.='<td>students must pick only one: <input type="checkbox" name="pickonenew" value="one" /><br />'; |
|
# $output.='Allow student to type extra info: <input type="checkbox" name="typeextranew" value="extra" /></td>'; |
|
# $output.='<td><input name="valuesnew" type="text" value="" /></td></tr>'; |
|
# $output.='<input type="hidden" name="serial" value="'.$next_meta.'" />'; |
|
# $output.='<input type="hidden" name="state" value="save" /></tr>'; |
|
$r->print(<<ENDenv); |
$r->print(<<ENDenv); |
<form method="post" action="/adm/parmset?action=setinstmeta" name="form"> |
<form method="post" action="/adm/parmset?action=setinstmeta" name="form"> |
|
|