Annotation of loncom/interface/lonsimplepage.pm, revision 1.28
1.1 www 1: # The LearningOnline Network
2: # Simple Page Editor
3: #
1.28 ! raeburn 4: # $Id: lonsimplepage.pm,v 1.27 2005/10/30 02:39:09 www Exp $
1.1 www 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;
1.6 matthew 36: use Apache::lonfeedback;
1.13 www 37: use Apache::lonlocal;
1.14 sakharuk 38: use Apache::lonprintout;
39: use Apache::lonxml;
1.1 www 40:
41: sub handler {
42: my $r = shift;
1.24 albertel 43: &Apache::loncommon::content_type($r,'text/html');
1.1 www 44: $r->send_http_header;
45: return OK if $r->header_only;
1.25 albertel 46: my $target=$env{'form.grade_target'};
1.1 www 47: # ------------------------------------------------------------ Print the screen
1.18 sakharuk 48: if ($target ne 'tex') {
1.23 albertel 49: my $html=&Apache::lonxml::xmlbegin();
1.14 sakharuk 50: $r->print(<<ENDDOCUMENT);
1.23 albertel 51: $html
1.1 www 52: <head>
53: <title>The LearningOnline Network with CAPA</title>
54: ENDDOCUMENT
1.14 sakharuk 55: } else {
1.25 albertel 56: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.14 sakharuk 57: }
1.28 ! raeburn 58: my (undef,undef,undef,undef,$marker,$caller)=split(/\//,$r->uri);
1.1 www 59: # Is this even in a course?
1.25 albertel 60: unless ($env{'request.course.id'}) {
1.18 sakharuk 61: if ($target ne 'tex') {
1.14 sakharuk 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: }
1.1 www 67: }
68:
1.28 ! raeburn 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: }
1.1 www 86:
87: unless ($marker) {
88: $r->print('<body>Invalid call</body>');
89: return OK;
90: }
91:
92: # --------------------------------------------------------- The syllabus fields
1.13 www 93: my %syllabusfields=&Apache::lonlocal::texthash(
1.1 www 94: 'aaa_title' => 'Page Title',
95: 'bbb_content' => 'Content',
96: 'ccc_webreferences' => 'Web References');
1.28 ! raeburn 97: if ($caller eq 'grppg') {
! 98: $syllabusfields{'abb_links'} = &mt('Functionality');
! 99: }
1.1 www 100:
1.7 www 101:
102: # ------------------------------------------------------------ Get query string
103: &Apache::loncommon::get_unprocessed_cgi
1.16 www 104: ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register']);
1.7 www 105: # ----------------------------------------------------- Force menu registration
106: my $addentries='';
1.25 albertel 107: if ($env{'form.register'}) {
1.7 www 108: $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
109: '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
110: $r->print(&Apache::lonmenu::registerurl(1));
111: }
1.1 www 112: # --------------------------------------------------------------- Force Student
113: my $forcestudent='';
1.25 albertel 114: if ($env{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
1.16 www 115: my $forceedit='';
1.25 albertel 116: if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.1 www 117:
1.7 www 118:
1.28 ! raeburn 119: my %syllabus=&Apache::lonnet::dump($caller.'_'.$marker,$dom,$crs);
1.1 www 120:
121: # --------------------------------------- There is such a user, get environment
122:
1.18 sakharuk 123: if ($target ne 'tex') {
1.28 ! raeburn 124: my $title = 'Course Page';
! 125: if ($caller eq 'grppg') {
! 126: $title = 'Group Page';
! 127: }
1.21 www 128: $r->print(&Apache::lonhtmlcommon::htmlareaheaders().
129: '</head>'.&Apache::loncommon::bodytag
1.28 ! raeburn 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: }
1.14 sakharuk 151: }
1.1 www 152:
1.28 ! raeburn 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: }
1.16 www 163: my $privileged=$allowed;
164: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
165: $forcestudent='student';
166: }
1.1 www 167:
1.18 sakharuk 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: }
1.25 albertel 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) {
1.18 sakharuk 180: if ($syllabus{'uploaded.photourl'}) {
181: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
182: }
1.28 ! raeburn 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: }
1.18 sakharuk 190: }
191: $syllabus{'uploaded.lastmodified'}=time;
1.28 ! raeburn 192: &Apache::lonnet::put($caller.'_'.$marker,\%syllabus,$dom,$crs);
1.18 sakharuk 193: }
1.25 albertel 194: if (($allowed) && ($env{'form.storesyl'})) {
1.18 sakharuk 195: foreach (keys %syllabusfields) {
1.25 albertel 196: my $field=$env{'form.'.$_};
1.21 www 197: chomp($field);
1.18 sakharuk 198: $field=~s/\s+$//s;
1.21 www 199: $field=~s/^\s+//s;
200: $field=~s/\<br\s*\/*\>$//s;
1.18 sakharuk 201: $field=&Apache::lonfeedback::clear_out_html($field,1);
202: $syllabus{$_}=$field;
203: }
204: $syllabus{'uploaded.lastmodified'}=time;
1.28 ! raeburn 205: &Apache::lonnet::put($caller.'_'.$marker,\%syllabus,$dom,$crs);
1.18 sakharuk 206: }
1.1 www 207:
208: # ---------------------------------------------------------------- Get syllabus
209: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.18 sakharuk 210: if ($syllabus{'uploaded.photourl'}) {
1.28 ! raeburn 211: &Apache::lonnet::allowuploaded('/adm/'.$caller,
1.19 sakharuk 212: $syllabus{'uploaded.photourl'});
1.20 albertel 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);
1.18 sakharuk 218: }
1.20 albertel 219: $r->print($image);
1.18 sakharuk 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{$_};
1.26 albertel 233: &Apache::lonfeedback::newline_to_br(\$message);
1.18 sakharuk 234: $message
235: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.22 www 236: if ($allowed) {
237: $message=&Apache::lonspeller::markeduptext($message);
238: }
1.27 www 239: $message=&Apache::lontexconvert::msgtexconverted($message);
1.28 ! raeburn 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 {
1.18 sakharuk 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>');
1.14 sakharuk 275: } else {
276: my $safeinit;
1.18 sakharuk 277: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
278: }
279: if ($allowed) {
280: if ($target ne 'tex') {
1.21 www 281: $r->print('<br /><textarea cols="80" rows="24" name="'.$_.'" id="'.$_.'">'.
1.18 sakharuk 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: }
1.14 sakharuk 288: }
1.18 sakharuk 289: }
290: }
291: }
1.25 albertel 292: if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
1.21 www 293: $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
294: ('bbb_content').'</form>');
1.18 sakharuk 295: }
1.25 albertel 296: if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
1.1 www 297: } else {
1.18 sakharuk 298: $r->print('<p>No page information provided.</p>');
1.1 www 299: }
1.25 albertel 300: if ($env{'form.grade_target'} ne 'tex') {
1.14 sakharuk 301: $r->print('</body></html>');
302: } else {
303: $r->print('\end{document}');
304: }
1.1 www 305: return OK;
1.28 ! raeburn 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:
1.1 www 364:
365: 1;
366: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>