File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.36: download - view: text, annotated - select for diffs
Wed Mar 29 20:07:00 2006 UTC (18 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Changes to function links on group page. Also, adding a javascript function to lonmenu to open a group chat window (called from Group chat link on group page).

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

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