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