version 1.122, 2013/05/10 17:49:11
|
version 1.125, 2013/05/15 17:47:57
|
Line 71 sub handler {
|
Line 71 sub handler {
|
} |
} |
# ------------------------------------- There is such a course, get environment |
# ------------------------------------- There is such a course, get environment |
my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum); |
my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum); |
|
my $crstype = &Apache::loncommon::course_type(); |
|
|
# ------------------------------------------------------------ Print the screen |
# ------------------------------------------------------------ Print the screen |
|
|
Line 117 sub handler {
|
Line 118 sub handler {
|
} |
} |
unless ($allowed && $forceedit) { |
unless ($allowed && $forceedit) { |
my $file=&Apache::lonnet::filelocation("",$item); |
my $file=&Apache::lonnet::filelocation("",$item); |
if ($file =~ /\.(sty|css|js|txt|tex|html?)$/) { |
if ($file =~ /\.(tex|x?html?)$/) { |
my $filetype; |
my $filetype = $1; |
if ($file =~ /\.(sty|css|js|txt|tex)$/) { |
|
$filetype=$1; |
|
} else { |
|
$filetype='html'; |
|
} |
|
my $result = ''; |
|
my $filecontents=&Apache::lonnet::getfile($file); |
my $filecontents=&Apache::lonnet::getfile($file); |
if ($filecontents eq -1) { |
if ($filecontents eq -1) { |
$r->print(&mt('Syllabus file unavailable')); |
$r->print(&mt('Syllabus file unavailable')); |
} elsif ($filetype eq 'html') { |
} elsif ($filetype eq 'tex') { |
|
my $result = &Apache::lontexconvert::converted(\$filecontents, |
|
$env{'form.texengine'}); |
|
my %args; |
|
&get_breadcrumbs($cdom,$cnum,$crstype,\%args); |
|
$r->print(&Apache::loncommon::start_page("Syllabus",undef,\%args). |
|
$result. |
|
&Apache::loncommon::end_page()); |
|
} else { |
my %mystyle; |
my %mystyle; |
&Apache::structuretags::reset_problem_globals(); |
&Apache::structuretags::reset_problem_globals(); |
my $oldfile = $env{'request.filename'}; |
my $oldfile = $env{'request.filename'}; |
$env{'request.filename'} = $item; |
$env{'request.filename'} = $item; |
$result = &Apache::lonxml::xmlparse($r,'web',$filecontents, |
my $result = &Apache::lonxml::xmlparse($r,'web',$filecontents, |
'',%mystyle); |
'',%mystyle); |
&Apache::structuretags::reset_problem_globals(); |
&Apache::structuretags::reset_problem_globals(); |
&Apache::lonhomework::finished_parsing(); |
&Apache::lonhomework::finished_parsing(); |
$env{'request.filename'} = $oldfile; |
$env{'request.filename'} = $oldfile; |
Line 153 sub handler {
|
Line 156 sub handler {
|
} |
} |
} |
} |
|
|
my $crstype = &Apache::loncommon::course_type(); |
|
|
|
# ------------------------------ The buck stops here: internal syllabus display |
# ------------------------------ The buck stops here: internal syllabus display |
# --------------------------------------------------------- The syllabus fields |
# --------------------------------------------------------- The syllabus fields |
Line 664 ENDSCRIPT
|
Line 666 ENDSCRIPT
|
{href=>$r->uri, |
{href=>$r->uri, |
text=>"Course syllabus"}); |
text=>"Course syllabus"}); |
$args->{'bread_crumbs'} = $brcrum; |
$args->{'bread_crumbs'} = $brcrum; |
} elsif ($env{'form.folderpath'} =~ /^supplemental/) { |
} else { |
|
&get_breadcrumbs($cdom,$cnum,$crstype,$args); |
|
} |
|
if ($allowed) { |
|
my %loaditem = ( |
|
onload => 'setTemplateBoxes();', |
|
); |
|
$args->{'add_entries'} = \%loaditem; |
|
} |
|
my $start_page = |
|
&Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args); |
|
if ($start_page) { |
|
$r->print($start_page); |
|
} |
|
} |
|
|
|
sub get_breadcrumbs{ |
|
my ($cdom,$cnum,$crstype,$args) = @_; |
|
return unless (ref($args) eq 'HASH'); |
|
if ($env{'form.folderpath'} =~ /^supplemental/) { |
my $title = $env{'form.title'}; |
my $title = $env{'form.title'}; |
if ($title eq '') { |
if ($title eq '') { |
$title = &mt('Syllabus'); |
$title = &mt('Syllabus'); |
Line 685 ENDSCRIPT
|
Line 706 ENDSCRIPT
|
]; |
]; |
} |
} |
} |
} |
if ($allowed) { |
return; |
my %loaditem = ( |
|
onload => 'setTemplateBoxes();', |
|
); |
|
$args->{'add_entries'} = \%loaditem; |
|
} |
|
my $start_page = |
|
&Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args); |
|
if ($start_page) { |
|
$r->print($start_page); |
|
} |
|
} |
} |
|
|
sub chooser { |
sub chooser { |
Line 817 sub syllabus_file_info {
|
Line 828 sub syllabus_file_info {
|
my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$item; |
my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$item; |
my ($filename) = ($item =~ m{([^/]+)$}); |
my ($filename) = ($item =~ m{([^/]+)$}); |
my $file=&Apache::lonnet::filelocation("",$item); |
my $file=&Apache::lonnet::filelocation("",$item); |
my $depbutton; |
my ($depbutton,$filetype,$editable); |
if ($file =~ /\.html?$/) { |
if ($file =~ /\.(xhtml|xml|tex|html|htm)$/) { |
|
$filetype=$1; |
|
} |
|
if ($filetype) { |
|
unless ($filetype eq 'tex') { |
|
$filetype='html'; |
|
} |
|
} |
|
if ($filetype eq 'html') { |
my $filecontents=&Apache::lonnet::getfile($file); |
my $filecontents=&Apache::lonnet::getfile($file); |
unless ($filecontents eq -1) { |
unless ($filecontents eq -1) { |
my $mm = new File::MMagic; |
my $mm = new File::MMagic; |
Line 833 sub syllabus_file_info {
|
Line 852 sub syllabus_file_info {
|
\%codebase, |
\%codebase, |
{'context' => 'rewrites', |
{'context' => 'rewrites', |
'ignore_remote_references' => 1,}); |
'ignore_remote_references' => 1,}); |
$depbutton = (' ' x 3). |
$editable = 1; |
&editfile_button($item,$context). |
|
&editbutton_js(); |
|
} |
} |
} |
} |
} |
} |
|
$depbutton = (' ' x 3). |
|
&editfile_button($item,$context,$editable). |
|
&editbutton_js(); |
return ($absurl,$filename,$depbutton); |
return ($absurl,$filename,$depbutton); |
} |
} |
|
|
Line 1059 sub save_changes {
|
Line 1079 sub save_changes {
|
$syllabus->{'uploaded.lastmodified'} = $now; |
$syllabus->{'uploaded.lastmodified'} = $now; |
my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum); |
my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum); |
if ($putres eq 'ok') { |
if ($putres eq 'ok') { |
my %storehash; |
($uploaded,$minimal,$external) = |
if ($courseenv->{'uploadedsyllabus'}) { |
&update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded, |
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus'); |
$minimal,$external); |
$storehash{'uploadedsyllabus'} = ''; |
|
} |
|
if ($courseenv->{'externalsyllabus'}) { |
|
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus'); |
|
$storehash{'externalsyllabus'} = ''; |
|
} |
|
if ($courseenv->{'minimalsyllabus'}) { |
|
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus'); |
|
$storehash{'minimalsyllabus'} = ''; |
|
} |
|
$storehash{'updatedsyllabus'} = $now; |
|
&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum); |
|
&Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now}); |
|
if (($courseenv->{'externalsyllabus'} || $courseenv->{'uploadedsyllabus'}) || |
|
($courseenv->{'minimalsyllabus'})) { |
|
undef($uploaded); |
|
undef($external); |
|
undef($minimal); |
|
} |
|
$output = '<div>'. |
$output = '<div>'. |
&Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')). |
&Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')). |
'</div>'; |
'</div>'; |
Line 1095 sub save_changes {
|
Line 1096 sub save_changes {
|
$output = '<div class="LC_info">'. |
$output = '<div class="LC_info">'. |
&mt('External URL unchanged.'). |
&mt('External URL unchanged.'). |
'</div>'; |
'</div>'; |
if ($uploaded) { |
($uploaded,$minimal,$external) = |
my $prefix; |
&update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded, |
my $home=&Apache::lonnet::homeserver($cnum,$cdom); |
$minimal,$external); |
if ($home ne 'no_host') { |
|
my $protocol = $Apache::lonnet::protocol{$home}; |
|
$protocol = 'http' if ($protocol ne 'https'); |
|
$prefix = $protocol.'://'.&Apache::lonnet::hostname($home); |
|
} |
|
unless ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus\E}) { |
|
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus'); |
|
&Apache::lonnet::put('environment',{uploadedsyllabus => ''}, |
|
$cdom,$cnum); |
|
undef($uploaded); |
|
} |
|
} |
|
} else { |
} else { |
$external=$env{'form.externalsyllabus'}; |
$external=$env{'form.externalsyllabus'}; |
$external =~ s/(`)//g; |
$external =~ s/(`)//g; |
Line 1121 sub save_changes {
|
Line 1110 sub save_changes {
|
$output = '<div>'. |
$output = '<div>'. |
&Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')). |
&Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')). |
'</div>'; |
'</div>'; |
if ($uploaded) { |
($uploaded,$minimal,$external) = |
my $prefix; |
&update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded, |
my $home=&Apache::lonnet::homeserver($cnum,$cdom); |
$minimal,$external); |
if ($home ne 'no_host') { |
|
my $protocol = $Apache::lonnet::protocol{$home}; |
|
$protocol = 'http' if ($protocol ne 'https'); |
|
$prefix = $protocol.'://'.&Apache::lonnet::hostname($home); |
|
} |
|
unless ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus\E}) { |
|
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus'); |
|
&Apache::lonnet::put('environment',{uploadedsyllabus => ''}, |
|
$cdom,$cnum); |
|
undef($uploaded); |
|
} |
|
} |
|
} else { |
} else { |
$output = '<div class="LC_error">'. |
$output = '<div class="LC_error">'. |
&mt('An error occurred storing the external URL: [_1]',$putres). |
&mt('An error occurred storing the external URL: [_1]',$putres). |
Line 1187 END
|
Line 1164 END
|
'portfolio/syllabus/loncapa.html'); |
'portfolio/syllabus/loncapa.html'); |
} |
} |
if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) { |
if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) { |
my $exturl; |
my $exturl = &home_http_host($cdom,$cnum); |
my $home=&Apache::lonnet::homeserver($cnum,$cdom); |
if ($exturl) { |
if ($home ne 'no_host') { |
$exturl .= $url; |
my $protocol = $Apache::lonnet::protocol{$home}; |
|
$protocol = 'http' if ($protocol ne 'https'); |
|
$exturl = $protocol.'://'.&Apache::lonnet::hostname($home).$url; |
|
} |
} |
my %storehash; |
my %storehash; |
if ($env{'form.choice'} eq 'minimal') { |
if ($env{'form.choice'} eq 'minimal') { |
Line 1224 END
|
Line 1198 END
|
$output .= &return_to_editor($cdom,$cnum); |
$output .= &return_to_editor($cdom,$cnum); |
$earlyout = 1; |
$earlyout = 1; |
} |
} |
|
($uploaded,$minimal,$external) = |
|
&update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded, |
|
$minimal,$external); |
} else { |
} else { |
$error = 1; |
$error = 1; |
$errormsg = $putres; |
$errormsg = $putres; |
Line 1273 END
|
Line 1250 END
|
return ($earlyout,$uploaded,$external,$minimal,$output); |
return ($earlyout,$uploaded,$external,$minimal,$output); |
} |
} |
|
|
|
sub update_syllabus_env { |
|
my ($cdom,$cnum,$courseenv,$saved,$uploaded,$minimal,$external) = @_; |
|
return ($uploaded,$minimal,$external) unless(ref($courseenv) eq 'HASH'); |
|
my $now = time; |
|
my (@envkeys,%storehash); |
|
if ($saved eq 'template') { |
|
if ($uploaded) { |
|
push(@envkeys,'uploaded'); |
|
} |
|
if ($minimal) { |
|
push(@envkeys,'minimal'); |
|
} |
|
if ($external) { |
|
push(@envkeys,'external'); |
|
} |
|
$storehash{'updatedsyllabus'} = $now; |
|
&Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now |
|
}); |
|
|
|
} elsif ($saved eq 'url') { |
|
my $prefix = &home_http_host($cdom,$cnum); |
|
if ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) { |
|
my $file = $1; |
|
if ($file eq 'loncapa.html') { |
|
if ($uploaded) { |
|
push(@envkeys,'uploaded'); |
|
} |
|
} elsif ($minimal) { |
|
push(@envkeys,'minimal'); |
|
} |
|
} else { |
|
if ($uploaded) { |
|
push(@envkeys,'uploaded'); |
|
} |
|
if ($minimal) { |
|
push(@envkeys,'minimal'); |
|
} |
|
} |
|
} elsif ($saved eq 'file') { |
|
if ($minimal) { |
|
push(@envkeys,'minimal'); |
|
} |
|
} elsif ($saved eq 'minimal') { |
|
if ($uploaded) { |
|
push(@envkeys,'uploaded'); |
|
} |
|
} |
|
if (@envkeys > 0) { |
|
foreach my $item (@envkeys) { |
|
my $key = $item.'syllabus'; |
|
if ($courseenv->{$key}) { |
|
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key); |
|
$storehash{$key} = ''; |
|
} |
|
if ($item eq 'uploaded') { |
|
undef($uploaded); |
|
} |
|
if ($item eq 'external') { |
|
undef($external); |
|
} |
|
if ($item eq 'minimal') { |
|
undef($minimal); |
|
} |
|
} |
|
} |
|
if (keys(%storehash) > 0) { |
|
&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum); |
|
} |
|
return ($uploaded,$minimal,$external); |
|
} |
|
|
|
sub home_http_host { |
|
my ($cdom,$cnum) = @_; |
|
my $home=&Apache::lonnet::homeserver($cnum,$cdom); |
|
if ($home ne 'no_host') { |
|
my $protocol = $Apache::lonnet::protocol{$home}; |
|
$protocol = 'http' if ($protocol ne 'https'); |
|
return $protocol.'://'.$home; |
|
} |
|
return; |
|
} |
|
|
sub process_upload { |
sub process_upload { |
my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_; |
my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_; |
my ($parseaction,$showupload,$mimetype); |
my ($parseaction,$showupload,$mimetype); |
Line 1358 sub return_to_editor {
|
Line 1417 sub return_to_editor {
|
} |
} |
|
|
sub editfile_button { |
sub editfile_button { |
my ($url,$context) = @_; |
my ($url,$context,$editable) = @_; |
my $edittext=&mt('Edit'); |
my $edittext=&mt('Edit'); |
my $deltext=&mt('Delete'); |
my $deltext=&mt('Delete'); |
return <<"END"; |
my $output; |
<input type="button" value="$edittext" onclick="javascript:gotoeditor('$url');" name="edit_$context" /> |
if ($editable) { |
|
$output = ' |
<input type="button" value="$deltext" onclick="javascript:dodelete('$context');" name="del_$context" /> |
<input type="button" value="'.$edittext.'" onclick="javascript:gotoeditor('."'$url'".');" name="edit_'.$context.'" /> |
|
'; |
|
} |
|
$output .= ' |
|
<input type="button" value="'.$deltext.'" onclick="javascript:dodelete('."'$context'".');" name="del_'.$context.'" /> |
<input type="hidden" value="" name="deleteuploaded" /> |
<input type="hidden" value="" name="deleteuploaded" /> |
END |
'; |
|
return $output; |
} |
} |
|
|
sub editbutton_js { |
sub editbutton_js { |