File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.41: download - view: text, annotated - select for diffs
Thu May 18 17:12:58 2006 UTC (18 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- coursegroups moved

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

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