Annotation of loncom/interface/lonsource.pm, revision 1.3

1.1       taceyjo1    1: # The LearningOnline Network with CAPA
1.2       albertel    2: # Souce Code handler
1.1       taceyjo1    3: #
1.3     ! www         4: # $Id: lonsource.pm,v 1.2 2004/06/12 04:44:31 albertel Exp $
1.1       taceyjo1    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: ###
                     29: 
                     30: 
                     31: package Apache::lonsource;
                     32: 
                     33: use strict;
                     34: use Apache::lonnet();
                     35: use Apache::loncommon();
                     36: use Apache::lonhtmlcommon();
                     37: use Apache::lonsequence();
                     38: use Apache::Constants qw(:common :http);
                     39: use Apache::lonmeta;
                     40: use Apache::File;
                     41: use Apache::lonlocal;
                     42: use HTML::Entities;
                     43: 
                     44: sub make_link {
1.2       albertel   45:     my ($filename) = @_;
                     46:     my $sourcelink = "http://".$ENV{'SERVER_NAME'}.
                     47: 	"/adm/source/?filename=".$filename;
                     48: 
                     49:     return $sourcelink;
1.1       taceyjo1   50: }
                     51: 
                     52: sub stage_2 {
1.2       albertel   53:     my ($r, $filename) = @_;
                     54:     $r->print("Coming Soon");
                     55:     return OK;
1.1       taceyjo1   56: }
                     57: 
                     58: sub print_item {
1.2       albertel   59:     my ($r, $filename) = @_;
                     60:     $filename = "/home/httpd/html".$filename;
                     61:     my $file_output = &Apache::lonnet::getfile($filename);
                     62:     my ($rows,$cols) = &Apache::edit::textarea_sizes(\$file_output);
                     63:     $r->print('<textarea rows="'.$rows.'" cols="'.$cols.'" name="editxmltext">'.
                     64: 	      &HTML::Entities::encode($file_output,'<>&"').'</textarea>');
                     65:     return OK;
1.1       taceyjo1   66: 	
                     67: }
                     68: 
                     69: 
                     70: sub handler { 
1.2       albertel   71:     my $r=shift;
1.3     ! www        72:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
        !            73: 					    ['filename']);
        !            74:     my $filename = $ENV{'form.filename'};
        !            75:     my $source = &Apache::lonnet::metadata($filename,'sourceavail');
        !            76:     if ($source ne 'open') {
        !            77: 	$ENV{'user.error.msg'}="$filename:cre:1:1:Source code not available";
        !            78: 	return HTTP_NOT_ACCEPTABLE;
        !            79:     }
        !            80:     if ((!&Apache::lonnet::allowed('cre')) ||
        !            81: 	(!&Apache::lonnet::allowed('bre',$filename))) {
        !            82: 	$ENV{'user.error.msg'}="$filename:bre:1:1:Access to resource denied";
        !            83: 	return HTTP_NOT_ACCEPTABLE;
        !            84:     }
        !            85:     if ($ENV{'form.action'} eq 'stage2') { 
1.2       albertel   86: 	&stage_2($r, $ENV{'form.filename'});
                     87:     } else {
1.1       taceyjo1   88: 	&Apache::loncommon::content_type($r,'text/html');
                     89: 	$r->send_http_header;
                     90: 	$r->print('		    <form name="copy" action="/adm/source/" target="_parent" method="post">
                     91: 				<input type="button" value="Close Window" name="close" onClick="window.close()">
                     92: 		      <input type="hidden" name="filename" value="'.$filename.'" />
                     93: 		      <input type="hidden" name="action" value="stage2" />
                     94: 	              <input type="submit" value="Copy to CSTR" />
                     95: 		    </form>');
                     96: 	$r->print('<hr />');
                     97: 	&print_item($r, $ENV{'form.filename'});
1.2       albertel   98:     }
                     99:     return OK;
1.1       taceyjo1  100: }
                    101: 
                    102: 1;
                    103: 	
1.2       albertel  104: 	

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>