File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.38: download - view: text, annotated - select for diffs
Mon Apr 10 19:59:54 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- start_page takes care of registering urls and the loadeventes/ unloadevents needed

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

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