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