File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.43: download - view: text, annotated - select for diffs
Fri Jul 7 21:25:02 2006 UTC (17 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Replacing grppg with smppg for file name of group home pages. Detection of group context from presence of course's domain and coursenumber in page URL (instead of a username and user domain).

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

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