File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.28: download - view: text, annotated - select for diffs
Tue Nov 15 22:05:04 2005 UTC (18 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Extension to allow simple page to be used to create/edit group homepages for course groups.

    1: # The LearningOnline Network
    2: # Simple Page Editor
    3: #
    4: # $Id: lonsimplepage.pm,v 1.28 2005/11/15 22:05:04 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: 
   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 ne 'tex') {
   49: 	my $html=&Apache::lonxml::xmlbegin();
   50: 	$r->print(<<ENDDOCUMENT);
   51: $html
   52: <head>
   53: <title>The LearningOnline Network with CAPA</title>
   54: ENDDOCUMENT
   55:     } else {
   56: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   57:     } 
   58:     my (undef,undef,undef,undef,$marker,$caller)=split(/\//,$r->uri);
   59: # Is this even in a course?
   60:     unless ($env{'request.course.id'}) {
   61: 	if ($target ne 'tex') {
   62: 	    $r->print('</head><body>Not in a course</body></html>');
   63: 	    return OK;
   64: 	} else {
   65: 	    $r->print('\textbf{Not in a course}\end{document}');
   66: 	}
   67:     }
   68: 
   69:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   70:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
   71:     my $grp_view_permission = &Apache::lonnet::allowed('vcg',
   72:                                                    $env{'request.course.id'});
   73: 
   74:     my %curr_group = ();
   75:     my %groupinfo = ();
   76:     if ($caller eq 'grppg') {
   77:         $marker =~ s/\W//g;
   78:         unless(&Apache::lonnet::get_coursegroups($dom,$crs,\%curr_group,
   79:                                                                     $marker)) {
   80:             $r->print('<body>Invalid group name</body>');
   81:             return OK;
   82:         }
   83:     } else {  
   84:         $marker=~s/\D//g;
   85:     }
   86: 
   87:     unless ($marker) {
   88: 	$r->print('<body>Invalid call</body>');
   89:         return OK;
   90:     }
   91: 
   92: # --------------------------------------------------------- The syllabus fields
   93:     my %syllabusfields=&Apache::lonlocal::texthash(
   94:        'aaa_title'         => 'Page Title',
   95:        'bbb_content'       => 'Content',
   96:        'ccc_webreferences' => 'Web References');
   97:     if ($caller eq 'grppg') {
   98:         $syllabusfields{'abb_links'} = &mt('Functionality');
   99:     }
  100: 
  101: 
  102: # ------------------------------------------------------------ Get query string
  103:     &Apache::loncommon::get_unprocessed_cgi
  104:                         ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register']);
  105: # ----------------------------------------------------- Force menu registration
  106:     my $addentries='';
  107:     if ($env{'form.register'}) {
  108:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
  109: 	   '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
  110:        $r->print(&Apache::lonmenu::registerurl(1));
  111:     }
  112: # --------------------------------------------------------------- Force Student
  113:     my $forcestudent='';
  114:     if ($env{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
  115:      my $forceedit='';
  116:      if ($env{'form.forceedit'}) { $forceedit='edit'; }
  117: 
  118: 
  119:     my %syllabus=&Apache::lonnet::dump($caller.'_'.$marker,$dom,$crs);
  120:        
  121: # --------------------------------------- There is such a user, get environment
  122: 
  123:     if ($target ne 'tex') {
  124:         my $title = 'Course Page';
  125:         if ($caller eq 'grppg') {
  126:             $title = 'Group Page';
  127:         }
  128: 	$r->print(&Apache::lonhtmlcommon::htmlareaheaders().
  129: 		  '</head>'.&Apache::loncommon::bodytag
  130: 		  ($title,$forcestudent,$addentries,'',$dom,$env{'form.register'}));
  131:     }
  132: 
  133:     if ($caller eq 'grppg') {
  134:         if (($grp_view_permission) || 
  135:                            (&Apache::loncommon::check_group_access($caller))) {
  136:             unless(&Apache::lonnet::allowed('vgh',
  137:                                       $env{'request.course.id'}.'/'.$marker)) {
  138:                 &display_group_links($r,$target,$marker,%groupinfo);
  139:                 return OK;
  140:             }
  141:         } else {
  142:             if ($target ne 'tex') {
  143:                 $r->print('</head><body>You do not currently have rights to
  144:                                         view this group.
  145:                            </body></html>');
  146:                 return OK;
  147:             } else {
  148:                 $r->print('\textbf{You do not currently have rights to view this group}\end{document}');
  149:             }
  150:         }
  151:     }
  152: 
  153:     my $allowed;
  154:     if ($caller eq 'grppg') {
  155:         $allowed  = $grp_view_permission;
  156:         unless ($allowed) {
  157:             $allowed = &Apache::lonnet::allowed('mgh',$env{'request.course.id'}.
  158:                                                                   '/'.$marker);
  159:         }
  160:     } else { 
  161:         $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  162:     }
  163:     my $privileged=$allowed;
  164:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  165: 	$forcestudent='student';
  166:     }
  167: 
  168:     if ($forcestudent or $target eq 'tex') { $allowed=0; }
  169:     
  170:     if ($allowed) {
  171: 	$r->print('<p>'.
  172: 		  &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>'.
  173: 		  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  174:     } elsif ($privileged and $target ne 'tex') {
  175: 	$r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'.&mt('Edit').'</font></a>');
  176:     } 
  177:     if (($env{'form.uploaddoc.filename'} and $target ne 'tex') &&
  178: 	($env{'form.storeupl'}) && ($allowed)) {
  179: 	if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  180: 	    if ($syllabus{'uploaded.photourl'}) {
  181: 		&Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  182: 	    }
  183:             if ($caller eq 'grppage') {
  184:                 $syllabus{'uploaded.photourl'}=&Apache::lonnet::userfileupload(
  185:                                               'uploaddoc',1,"grouppage/$marker");
  186:             } else {
  187: 	        $syllabus{'uploaded.photourl'}=
  188: 		     &Apache::lonnet::userfileupload('uploaddoc',1,'simplepage');
  189:             }
  190: 	}
  191: 	$syllabus{'uploaded.lastmodified'}=time;
  192: 	&Apache::lonnet::put($caller.'_'.$marker,\%syllabus,$dom,$crs);
  193:     }
  194:     if (($allowed) && ($env{'form.storesyl'})) {
  195: 	foreach (keys %syllabusfields) {
  196: 	    my $field=$env{'form.'.$_};
  197: 	    chomp($field);
  198: 	    $field=~s/\s+$//s;
  199: 	    $field=~s/^\s+//s;
  200: 	    $field=~s/\<br\s*\/*\>$//s;
  201: 	    $field=&Apache::lonfeedback::clear_out_html($field,1);
  202: 	    $syllabus{$_}=$field;
  203: 	}
  204: 	$syllabus{'uploaded.lastmodified'}=time;
  205: 	&Apache::lonnet::put($caller.'_'.$marker,\%syllabus,$dom,$crs);
  206:     }
  207: 
  208: # ---------------------------------------------------------------- Get syllabus
  209:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  210: 	if ($syllabus{'uploaded.photourl'}) {
  211: 	    &Apache::lonnet::allowuploaded('/adm/'.$caller,
  212: 					   $syllabus{'uploaded.photourl'});
  213: 	    
  214: 	    my $image='<img src="'.$syllabus{'uploaded.photourl'}.'"
  215:                             align="right" />';
  216: 	    if ($target eq 'tex') {
  217: 		$image=&Apache::lonxml::xmlparse($r,'tex',$image);
  218: 	    }
  219: 	    $r->print($image);
  220: 	}
  221: 	if ($allowed) {
  222: 	    $r->print(
  223: 		      '<form method="post" enctype="multipart/form-data">'.
  224: 		      '<input type="hidden" name="forceedit" value="edit" />'.
  225: 		      '<h3>Upload a Photo</h3>'.
  226: 		      '<input type="file" name="uploaddoc" size="50">'.
  227: 		      '<input type="submit" name="storeupl" value="Upload">'.
  228: 		      '</form><form method="post">');
  229: 	}
  230: 	foreach (sort keys %syllabusfields) {
  231: 	    if (($syllabus{$_}) || ($allowed)) {
  232: 		my $message=$syllabus{$_};
  233: 		&Apache::lonfeedback::newline_to_br(\$message);
  234: 		$message
  235: 		    =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  236: 		if ($allowed) {
  237: 		    $message=&Apache::lonspeller::markeduptext($message);
  238: 		}
  239: 		$message=&Apache::lontexconvert::msgtexconverted($message);
  240:                 if ($_ eq 'abb_links' && $caller eq 'grppg') {
  241:                     $r->print('<br /><input type="hidden" name="'.$_.
  242:                                           '" value="'.$syllabus{$_}.'" />');
  243:                     &display_group_links($r,$target,$marker,%groupinfo);
  244:                     $r->print('<br />');
  245:                 } elsif ($_ eq 'aaa_title') {
  246:                     if ($target ne 'tex') {
  247:                         $r->print('<h1>'.$message.'</h1>');
  248:                     } else {
  249:                         my $safeinit;
  250:                         $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
  251:                     }
  252:                     if ($allowed) {
  253:                         if ($env{'form.grade_target'} ne 'tex') {
  254:                             $r->print(
  255:                                       '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
  256:                                       $syllabus{$_}.
  257:                                       '</textarea><input type="submit" name="storesyl" value="Store" />');
  258:                         } else {
  259:                             my $safeinit;
  260:                             $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
  261:                         }
  262:                     }
  263:                 } else {
  264: 		    if (($_ ne 'bbb_content') || ($allowed)) {
  265: 			if ($target ne 'tex') {
  266: 			    $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
  267: 			} else {
  268: 			    my $safeinit;
  269: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$_}.'</h3>'));
  270: 			}
  271: 		    }
  272: 		    if ($target ne 'tex') {
  273: 			$r->print('<blockquote>'.
  274: 				  $message.'</blockquote>');
  275: 		    } else {
  276: 			my $safeinit;
  277: 			$r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
  278: 		    }
  279: 		    if ($allowed) {
  280: 			if ($target ne 'tex') {
  281: 			    $r->print('<br /><textarea cols="80" rows="24" name="'.$_.'" id="'.$_.'">'.
  282: 				      $syllabus{$_}.
  283: 				      '</textarea><input type="submit" name="storesyl" value="Store" />');
  284: 			} else {
  285: 			    my $safeinit;
  286: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
  287: 			}
  288: 		    }
  289: 		}
  290: 	    }
  291: 	}
  292: 	if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
  293: 	    $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
  294: 		      ('bbb_content').'</form>');
  295: 	}
  296: 	if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
  297:     } else {
  298: 	$r->print('<p>No page information provided.</p>');
  299:     }
  300:     if ($env{'form.grade_target'} ne 'tex') {
  301: 	$r->print('</body></html>');
  302:     } else {
  303: 	$r->print('\end{document}');
  304:     }
  305:     return OK;
  306: }
  307: 
  308: sub display_group_links {
  309:     my ($r,$target,$marker,%groupinfo) = @_;
  310:     my @available = ();
  311:                                                                                    
  312:     my %menu = ();
  313:     %{$menu{'email'}} = (
  314:                         text => 'Group e-mail',
  315:                         href => '/adm/email?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/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 = 'No group functionality (e.g., e-mail, discussion,chat or file upload) is currently available to you in this group: '.$marker;
  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>