Annotation of loncom/publisher/loncoursepub.pm, revision 1.1
1.1 ! raeburn 1: # The LearningOnline Network with CAPA
! 2: # Handler to store uploaded files etc. in Course's Authoring
! 3: # Space,
! 4: #
! 5: # $Id: loncoursepub.pm,v 1.1 2016/06/30 15:36:11 raeburn Exp $
! 6: #
! 7: # Copyright Michigan State University Board of Trustees
! 8: #
! 9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 10: #
! 11: # LON-CAPA is free software; you can redistribute it and/or modify
! 12: # it under the terms of the GNU General Public License as published by
! 13: # the Free Software Foundation; either version 2 of the License, or
! 14: # (at your option) any later version.
! 15: #
! 16: # LON-CAPA is distributed in the hope that it will be useful,
! 17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 19: # GNU General Public License for more details.
! 20: #
! 21: # You should have received a copy of the GNU General Public License
! 22: # along with LON-CAPA; if not, write to the Free Software
! 23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 24: #
! 25: # /home/httpd/html/adm/gpl.txt
! 26: #
! 27: # http://www.lon-capa.org/
! 28: #
! 29:
! 30: package Apache::loncoursepub;
! 31:
! 32: use strict;
! 33: use Apache::Constants qw(:common :http :methods);
! 34: use Apache::lonnet;
! 35: use Apache::loncommon();
! 36: use Apache::lonpublisher;
! 37: use Apache::londocs;
! 38: use Apache::lonlocal;
! 39: use LONCAPA qw(:DEFAULT :match);
! 40:
! 41: sub handler {
! 42: my $r = shift;
! 43: &Apache::loncommon::content_type($r,'text/html');
! 44: $r->send_http_header;
! 45: if ($env{'request.course.id'}) {
! 46: my $newurl;
! 47: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 48: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 49: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
! 50: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['LC_uploadcrsres']);
! 51: my $suffix = $env{'form.LC_uploadcrsres'};
! 52: my $containerfile = $env{'form.filename_'.$suffix};
! 53: if ($containerfile =~ m{^(/priv/\Q$cdom/$cnum\E)}) {
! 54: my $toppath = $1;
! 55: if ($suffix) {
! 56: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
! 57: my $newfilename = $env{'form.uploadcrsres_'.$suffix.'.filename'};
! 58: $newfilename =~ s/(\s+$|^\s+)//g;
! 59: $newfilename =~ s/[\#\?&%\":]//g;
! 60: $newfilename =~ s/\.(\d+)(\.\w+)$/$2/;
! 61: my $relpath = $env{'form.crsauthorpath_'.$suffix};
! 62: my $newsubdir;
! 63: if ($env{'form.newsubdir_'.$suffix}) {
! 64: $newsubdir = $env{'form.newsubdirname_'.$suffix};
! 65: }
! 66: if ($newfilename ne '') {
! 67: my $path = $londocroot.$toppath;
! 68: my $redirect = &Apache::londocs::finishnewprob($toppath,$path,$relpath,$newsubdir,$newfilename);
! 69: if ($redirect) {
! 70: my $url = $redirect;
! 71: my $srcfile = $londocroot.$url;
! 72: $url =~ s{^/priv/}{/res/};
! 73: my $targetfile = $londocroot.$url;
! 74: if (open(my $fh,'>'.$srcfile)) {
! 75: print $fh $env{'form.uploadcrsres_'.$suffix};
! 76: close($fh);
! 77: $url =~ s{^/priv/}{/res/};
! 78: my $targetfile = $londocroot.$url;
! 79: my $nokeyref = &Apache::lonpublisher::getnokey($Apache::lonnet::perlvar{'lonIncludes'});
! 80: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
! 81: $newurl = $url;
! 82: }
! 83: }
! 84: }
! 85: }
! 86: }
! 87: $r->print(<<"END");
! 88: <html>
! 89: <head>
! 90: <script type="text/javascript">
! 91: window.onload=top.uploadDone('$suffix','$newurl');
! 92: </script>
! 93: <body></body>
! 94: </html>
! 95: END
! 96: }
! 97: }
! 98: return OK;
! 99: }
! 100:
! 101: 1;
! 102:
! 103: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>