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