File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.34: download - view: text, annotated - select for diffs
Tue Mar 21 21:07:31 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- using the loncommon 'simple_error_page'

    1: # The LearningOnline Network
    2: # Simple Page Editor
    3: #
    4: # $Id: lonsimplepage.pm,v 1.34 2006/03/21 21:07:31 albertel Exp $
    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: package Apache::lonsimplepage;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::loncommon;
   34: use Apache::lonnet;
   35: use Apache::lontexconvert;
   36: use Apache::lonfeedback;
   37: use Apache::lonlocal;
   38: use Apache::lonprintout;
   39: use Apache::lonxml;
   40: 
   41: sub handler {
   42:     my $r = shift;
   43:     &Apache::loncommon::content_type($r,'text/html');
   44:     $r->send_http_header;
   45:     return OK if $r->header_only;
   46:     my $target=$env{'form.grade_target'};
   47: # ------------------------------------------------------------ Print the screen
   48:     if ($target eq 'tex') {
   49: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   50:     } 
   51:     my (undef,undef,undef,undef,$marker,$caller)=split(/\//,$r->uri);
   52: # Is this even in a course?
   53:     unless ($env{'request.course.id'}) {
   54: 	if ($target ne 'tex') {
   55: 	    return &Apache::loncommon::simple_error_page($r,'',
   56: 							 'Not in a course');
   57: 	} else {
   58: 	    $r->print('\textbf{Not in a course}\end{document}');
   59: 	}
   60:     }
   61: 
   62:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   63:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
   64:     my $grp_view_permission = &Apache::lonnet::allowed('vcg',
   65:                                                    $env{'request.course.id'});
   66:     my $namespace;
   67: 
   68:     my %curr_group = ();
   69:     my %groupinfo = ();
   70:     if ($caller eq 'grppg') {
   71:         $marker =~ s/\W//g;
   72:         $namespace = 'grppage_'.$marker;
   73:         my %curr_groups;
   74:         if (!&Apache::loncommon::coursegroups(\%curr_groups,$dom,$crs,$marker)) {
   75: 	    return &Apache::loncommon::simple_error_page($r,'',
   76: 							 'Invalid group name');
   77:         }
   78:         %groupinfo = 
   79: 	    &Apache::loncommon::get_group_settings($curr_groups{$marker});
   80:     } else {  
   81:         $marker=~s/\D//g;
   82:         $namespace = 'smppage_'.$marker;
   83:     }
   84: 
   85:     if (!$marker) {
   86: 	return &Apache::loncommon::simple_error_page($r,'','Invalid call');
   87:     }
   88: 
   89: # --------------------------------------------------------- The syllabus fields
   90:     my %syllabusfields=&Apache::lonlocal::texthash(
   91:        'aaa_title'         => 'Page Title',
   92:        'bbb_content'       => 'Content',
   93:        'ccc_webreferences' => 'Web References');
   94:     if ($caller eq 'grppg') {
   95:         $syllabusfields{'abb_links'} = &mt('Functionality');
   96:     }
   97: 
   98: 
   99: # ------------------------------------------------------------ Get query string
  100:     &Apache::loncommon::get_unprocessed_cgi
  101:                         ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register']);
  102: # ----------------------------------------------------- Force menu registration
  103:     my $addentries='';
  104:     if ($env{'form.register'}) {
  105:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
  106: 	   '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
  107:        $r->print(&Apache::lonmenu::registerurl(1));
  108:     }
  109: # --------------------------------------------------------------- Force Student
  110:     my $forcestudent='';
  111:     if ($env{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
  112:      my $forceedit='';
  113:      if ($env{'form.forceedit'}) { $forceedit='edit'; }
  114: 
  115:    
  116:     my %syllabus=&Apache::lonnet::dump($namespace,$dom,$crs);
  117:        
  118: # --------------------------------------- There is such a user, get environment
  119: 
  120:     if ($target ne 'tex') {
  121:         my $title = 'Course Page';
  122:         if ($caller eq 'grppg') {
  123:             $title = 'Group Page';
  124:         }
  125: 	$r->print(&Apache::lonhtmlcommon::htmlareaheaders().
  126: 		  &Apache::loncommon::endheadtag().
  127: 		  &Apache::loncommon::bodytag($title,$forcestudent,$addentries,
  128: 					      '',$dom,$env{'form.register'}));
  129:     }
  130: 
  131:     if ($caller eq 'grppg') {
  132:         if (($grp_view_permission) || 
  133:                            (&Apache::loncommon::check_group_access($caller))) {
  134:             unless(&Apache::lonnet::allowed('vgh',
  135:                                       $env{'request.course.id'}.'/'.$marker)) {
  136:                 &display_group_links($r,$target,$marker,'view',%groupinfo);
  137:                 return OK;
  138:             }
  139:         } else {
  140:             if ($target ne 'tex') {
  141:                 $r->print(&Apache::loncommon::endheadtag().
  142: 			  &Apache::loncommon::bodytag().
  143: 			  'You do not currently have rights to view this group.'.
  144: 			  &Apache::loncommon::end_page());
  145:                 return OK;
  146:             } else {
  147:                 $r->print('\textbf{You do not currently have rights to view this group}\end{document}');
  148:             }
  149:         }
  150:     }
  151: 
  152:     my $allowed;
  153:     if ($caller eq 'grppg') {
  154:         $allowed  = $grp_view_permission;
  155:         unless ($allowed) {
  156:             $allowed = &Apache::lonnet::allowed('mgh',$env{'request.course.id'}.
  157:                                                                   '/'.$marker);
  158:         }
  159:     } else { 
  160:         $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  161:     }
  162:     my $privileged=$allowed;
  163:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  164: 	$forcestudent='student';
  165:     }
  166: 
  167:     if ($forcestudent or $target eq 'tex') { $allowed=0; }
  168:     
  169:     if ($allowed) {
  170: 	$r->print('<p>'.
  171: 		  &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'<br /><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Student View').'</font></a>'.
  172: 		  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  173:     } elsif ($privileged and $target ne 'tex') {
  174: 	$r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'.&mt('Edit').'</font></a>');
  175:     } 
  176:     if (($env{'form.uploaddoc.filename'} and $target ne 'tex') &&
  177: 	($env{'form.storeupl'}) && ($allowed)) {
  178: 	if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  179: 	    if ($syllabus{'uploaded.photourl'}) {
  180: 		&Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  181: 	    }
  182:             if ($caller eq 'grppage') {
  183:                 $syllabus{'uploaded.photourl'}=&Apache::lonnet::userfileupload(
  184:                                               'uploaddoc',1,"grouppage/$marker");
  185:             } else {
  186: 	        $syllabus{'uploaded.photourl'}=
  187: 		     &Apache::lonnet::userfileupload('uploaddoc',1,'simplepage');
  188:             }
  189: 	}
  190: 	$syllabus{'uploaded.lastmodified'}=time;
  191: 	&Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
  192:     }
  193:     if (($allowed) && ($env{'form.storesyl'})) {
  194: 	foreach (keys %syllabusfields) {
  195: 	    my $field=$env{'form.'.$_};
  196: 	    chomp($field);
  197: 	    $field=~s/\s+$//s;
  198: 	    $field=~s/^\s+//s;
  199: 	    $field=~s/\<br\s*\/*\>$//s;
  200: 	    $field=&Apache::lonfeedback::clear_out_html($field,1);
  201: 	    $syllabus{$_}=$field;
  202: 	}
  203: 	$syllabus{'uploaded.lastmodified'}=time;
  204: 	&Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
  205:     }
  206: 
  207: # ---------------------------------------------------------------- Get syllabus
  208:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  209: 	if ($syllabus{'uploaded.photourl'}) {
  210: 	    &Apache::lonnet::allowuploaded('/adm/'.$caller,
  211: 					   $syllabus{'uploaded.photourl'});
  212: 	    
  213: 	    my $image='<img src="'.$syllabus{'uploaded.photourl'}.'"
  214:                             align="right" />';
  215: 	    if ($target eq 'tex') {
  216: 		$image=&Apache::lonxml::xmlparse($r,'tex',$image);
  217: 	    }
  218: 	    $r->print($image);
  219: 	}
  220: 	if ($allowed) {
  221: 	    $r->print(
  222: 		      '<form method="post" enctype="multipart/form-data">'.
  223: 		      '<input type="hidden" name="forceedit" value="edit" />'.
  224: 		      '<h3>Upload a Photo</h3>'.
  225: 		      '<input type="file" name="uploaddoc" size="50">'.
  226: 		      '<input type="submit" name="storeupl" value="Upload">'.
  227: 		      '</form><form method="post">');
  228: 	}
  229: 	foreach (sort keys %syllabusfields) {
  230: 	    if (($syllabus{$_}) || ($allowed)) {
  231: 		my $message=$syllabus{$_};
  232: 		&Apache::lonfeedback::newline_to_br(\$message);
  233: 		$message
  234: 		    =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  235: 		if ($allowed) {
  236: 		    $message=&Apache::lonspeller::markeduptext($message);
  237: 		}
  238: 		$message=&Apache::lontexconvert::msgtexconverted($message);
  239:                 if ($_ eq 'abb_links' && $caller eq 'grppg') {
  240:                     $r->print('<br /><input type="hidden" name="'.$_.
  241:                                           '" value="'.$syllabus{$_}.'" />');
  242:                     &display_group_links($r,$target,$marker,'edit',%groupinfo);
  243:                     $r->print('<br />');
  244:                 } elsif ($_ eq 'aaa_title') {
  245:                     if ($target ne 'tex') {
  246:                         $r->print('<h1>'.$message.'</h1>');
  247:                     } else {
  248:                         my $safeinit;
  249:                         $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
  250:                     }
  251:                     if ($allowed) {
  252:                         if ($env{'form.grade_target'} ne 'tex') {
  253:                             $r->print(
  254:                                       '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
  255:                                       $syllabus{$_}.
  256:                                       '</textarea><input type="submit" name="storesyl" value="Store" />');
  257:                         } else {
  258:                             my $safeinit;
  259:                             $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
  260:                         }
  261:                     }
  262:                 } else {
  263: 		    if (($_ ne 'bbb_content') || ($allowed)) {
  264: 			if ($target ne 'tex') {
  265: 			    $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
  266: 			} else {
  267: 			    my $safeinit;
  268: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$_}.'</h3>'));
  269: 			}
  270: 		    }
  271: 		    if ($target ne 'tex') {
  272: 			$r->print('<blockquote>'.
  273: 				  $message.'</blockquote>');
  274: 		    } else {
  275: 			my $safeinit;
  276: 			$r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
  277: 		    }
  278: 		    if ($allowed) {
  279: 			if ($target ne 'tex') {
  280: 			    $r->print('<br /><textarea cols="80" rows="24" name="'.$_.'" id="'.$_.'">'.
  281: 				      $syllabus{$_}.
  282: 				      '</textarea><input type="submit" name="storesyl" value="Store" />');
  283: 			} else {
  284: 			    my $safeinit;
  285: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
  286: 			}
  287: 		    }
  288: 		}
  289: 	    }
  290: 	}
  291: 	if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
  292: 	    $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
  293: 		      ('bbb_content').'</form>');
  294: 	}
  295: 	if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
  296:     } else {
  297: 	$r->print('<p>No page information provided.</p>');
  298:     }
  299:     if ($env{'form.grade_target'} ne 'tex') {
  300: 	$r->print(&Apache::loncommon::end_page());
  301:     } else {
  302: 	$r->print('\end{document}');
  303:     }
  304:     return OK;
  305: }
  306: 
  307: sub display_group_links {
  308:     my ($r,$target,$marker,$context,%groupinfo) = @_;
  309:     my @available = ();
  310:     my %menu = ();
  311:     %{$menu{'email'}} = (
  312:                         text => 'Group e-mail',
  313:                         href => '/adm/email?group='.$marker,
  314:                       );
  315:     %{$menu{'discussion'}} = (
  316:                         text => 'Discussion Boards',
  317:                         href => '/adm/groupboards?group='.$marker,
  318:                       );
  319:     %{$menu{'chat'}} = (
  320:                         text => 'Group chat',
  321:                         href => "javascript:group_chat('$marker')",
  322:                       );
  323:     %{$menu{'files'}} = (
  324:                         text => 'File repository',
  325:                         href => '/adm/portfolio?group='.$marker,
  326:                       );
  327:     %{$menu{'roster'}} = (
  328:                         text => 'Membership roster',
  329:                         href => '/adm/grouproster?group='.$marker,
  330:                       );
  331:     foreach my $tool (sort(keys(%menu))) {
  332:         if ($groupinfo{functions}{$tool} eq 'on') {
  333:             push(@available,$tool);
  334:         }
  335:     }
  336:     if (@available > 0) {
  337:         my $output = '<table cellspacing="4" cellpadding="4"><tr>';
  338:         foreach my $tool (@available) {
  339:             if ($target eq 'tex') {
  340:                 $output .= '<td>'.$menu{$tool}{text}.'</td>';
  341:             } else {
  342:                 $output .= '<td><a href="'.$menu{$tool}{href}.'">'.
  343:                            $menu{$tool}{text}.'</a></td>';
  344:             }
  345:         }
  346:         $output .= '</tr></table>';
  347:         if ($target eq 'tex') {
  348:             $r->print(&Apache::lonxml::xmlparse($r,'tex','Available functions<br /><br />'.$output));
  349:         } else {
  350:             $r->print('<h3>Functions</h3>'.$output);
  351:         }
  352:     } else {
  353:         my $output;
  354:         if ($context eq 'edit') {
  355:             $output = 'No group functionality';
  356:         } else {  
  357:             $output = 'No group functionality (e.g., e-mail, discussion, chat or file upload) is currently available to you in this group: '.$marker;
  358:         }
  359:         if ($target eq 'tex') {
  360:             $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
  361:         } else {
  362:             $r->print($output);
  363:         }
  364:     }
  365: }
  366:  
  367: 
  368: 1;
  369: __END__

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