Annotation of loncom/interface/lonsimplepage.pm, revision 1.49
1.1 www 1: # The LearningOnline Network
2: # Simple Page Editor
3: #
1.49 ! raeburn 4: # $Id: lonsimplepage.pm,v 1.48 2006/10/23 18:48:47 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.40 raeburn 40: use Apache::longroup;
1.47 albertel 41: use HTML::Entities();
1.44 raeburn 42: use LONCAPA;
1.1 www 43:
44: sub handler {
45: my $r = shift;
1.24 albertel 46: &Apache::loncommon::content_type($r,'text/html');
1.1 www 47: $r->send_http_header;
48: return OK if $r->header_only;
1.25 albertel 49: my $target=$env{'form.grade_target'};
1.1 www 50: # ------------------------------------------------------------ Print the screen
1.34 albertel 51: if ($target eq 'tex') {
1.25 albertel 52: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.14 sakharuk 53: }
1.45 raeburn 54: my (undef,undef,$udom,$uname,$marker)=split(/\//,$r->uri);
1.1 www 55: # Is this even in a course?
1.25 albertel 56: unless ($env{'request.course.id'}) {
1.18 sakharuk 57: if ($target ne 'tex') {
1.37 albertel 58: &Apache::loncommon::simple_error_page($r,'','Not in a course');
1.14 sakharuk 59: } else {
60: $r->print('\textbf{Not in a course}\end{document}');
61: }
1.37 albertel 62: return OK;
1.1 www 63: }
64:
1.28 raeburn 65: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
66: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.45 raeburn 67: my ($namespace,$group,$group_desc,$group_home_view,$group_home_edit,
68: $group_view_perm,$group_edit_perm);
1.28 raeburn 69: my %curr_group = ();
70: my %groupinfo = ();
1.43 raeburn 71: if ($dom && $crs && ($udom eq $dom) && ($uname eq $crs)) {
1.28 raeburn 72: $marker =~ s/\W//g;
1.43 raeburn 73: $group = $marker;
74: my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
1.39 albertel 75: if (!%curr_groups) {
1.37 albertel 76: &Apache::loncommon::simple_error_page($r,'','Invalid group name');
77: return OK;
1.28 raeburn 78: }
1.34 albertel 79: %groupinfo =
1.43 raeburn 80: &Apache::longroup::get_group_settings($curr_groups{$group});
1.45 raeburn 81: $group_desc = &unescape($groupinfo{'description'});
1.43 raeburn 82: $namespace = 'grppage_'.$group;
83: } else {
1.28 raeburn 84: $marker=~s/\D//g;
1.29 raeburn 85: $namespace = 'smppage_'.$marker;
1.28 raeburn 86: }
1.1 www 87:
1.32 albertel 88: if (!$marker) {
1.37 albertel 89: &Apache::loncommon::simple_error_page($r,'','Invalid call');
90: return OK;
1.1 www 91: }
92:
93: # --------------------------------------------------------- The syllabus fields
1.13 www 94: my %syllabusfields=&Apache::lonlocal::texthash(
1.1 www 95: 'aaa_title' => 'Page Title',
96: 'bbb_content' => 'Content',
97: 'ccc_webreferences' => 'Web References');
1.43 raeburn 98: if ($group ne '') {
1.45 raeburn 99: $syllabusfields{'abb_links'} = &mt('Available Group Tools');
1.28 raeburn 100: }
1.1 www 101:
1.7 www 102:
103: # ------------------------------------------------------------ Get query string
104: &Apache::loncommon::get_unprocessed_cgi
1.44 raeburn 105: ($ENV{'QUERY_STRING'},['forcestudent','forceedit',
106: 'register','ref']);
1.1 www 107: # --------------------------------------------------------------- Force Student
108: my $forcestudent='';
1.25 albertel 109: if ($env{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
1.38 albertel 110: my $forceedit='';
111: if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.1 www 112:
1.45 raeburn 113: my $refarg;
114: if ($env{'form.ref'}) {
115: $refarg = '&ref='.$env{'form.ref'};
116: }
1.29 raeburn 117:
118: my %syllabus=&Apache::lonnet::dump($namespace,$dom,$crs);
1.1 www 119:
120: # --------------------------------------- There is such a user, get environment
121:
1.18 sakharuk 122: if ($target ne 'tex') {
1.28 raeburn 123: my $title = 'Course Page';
1.43 raeburn 124: if ($group ne '') {
1.28 raeburn 125: $title = 'Group Page';
126: }
1.35 albertel 127: my $start_page =
128: &Apache::loncommon::start_page($title,undef,
129: {'function' => $forcestudent,
130: 'domain' => $dom,
131: 'force_register' =>
132: $env{'form.register'},});
133: $r->print($start_page);
1.28 raeburn 134: }
135:
1.43 raeburn 136: if ($group ne '') {
1.45 raeburn 137: my $group_view_perm =
138: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
139: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
140: $group_edit_perm =
141: &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
142: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
143: $group_home_view = &Apache::lonnet::allowed('vgh',
144: $env{'request.course.id'}.'/'.$group);
145: $group_home_edit = &Apache::lonnet::allowed('mgh',
146: $env{'request.course.id'}.'/'.$group);
147: if ($group_view_perm || $group_edit_perm || $group_home_view ||
148: $group_home_edit || &Apache::longroup::check_group_access($group)) {
149: if (($env{'form.ref'} eq 'grouplist') && ($target ne 'tex')) {
150: $r->print(&grouppage_breadcrumbs($dom,$crs,$group,$group_desc));
151: }
152: if ((!$group_home_edit) && (!$group_home_view) &&
1.49 ! raeburn 153: (!$group_view_perm) && (!$group_edit_perm)) {
1.45 raeburn 154: &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
1.49 ! raeburn 155: if ($env{'form.grade_target'} ne 'tex') {
! 156: $r->print(&Apache::loncommon::end_page());
! 157: } else {
! 158: $r->print('\end{document}');
! 159: }
1.28 raeburn 160: return OK;
161: }
162: } else {
1.35 albertel 163: my $msg =
164: &mt('You do not currently have rights to view this group.');
1.28 raeburn 165: if ($target ne 'tex') {
1.35 albertel 166: $r->print("<p>$msg</p>".
1.32 albertel 167: &Apache::loncommon::end_page());
1.28 raeburn 168: } else {
1.35 albertel 169: $r->print('\textbf{'.$msg.'}\end{document}');
1.28 raeburn 170: }
1.35 albertel 171: return OK;
1.28 raeburn 172: }
1.49 ! raeburn 173: my ($blocked,$blocktext) =
! 174: &Apache::loncommon::blocking_status('groups');
! 175: if ($blocked) {
! 176: $r->print($blocktext);
! 177: $r->print(&Apache::loncommon::end_page());
! 178: return OK;
! 179: }
1.14 sakharuk 180: }
1.1 www 181:
1.28 raeburn 182: my $allowed;
1.45 raeburn 183:
1.43 raeburn 184: if ($group ne '') {
1.45 raeburn 185: $allowed = $group_edit_perm;
1.42 raeburn 186: if (!$allowed) {
1.45 raeburn 187: $allowed = $group_home_edit;
1.28 raeburn 188: }
189: } else {
190: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
191: }
1.16 www 192: my $privileged=$allowed;
193: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
194: $forcestudent='student';
195: }
1.1 www 196:
1.18 sakharuk 197: if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.46 raeburn 198:
1.18 sakharuk 199: if ($allowed) {
200: $r->print('<p>'.
1.45 raeburn 201: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'<br /><a href="'.$r->uri.'?forcestudent=1'.$refarg.'"><font size="+1">'.&mt('Show Student View').'</font></a>'.
1.18 sakharuk 202: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
203: } elsif ($privileged and $target ne 'tex') {
1.45 raeburn 204: my $edittext = &mt('Edit');
205: if ($group ne '') {
206: $edittext = &mt('Edit Group Homepage');
207: }
208: $r->print('<a href="'.$r->uri.'?forceedit=edit'.$refarg.'"><font size="+1">'.$edittext.'</font></a>');
209: if ($group ne '') {
210: if ($group_edit_perm) {
211: $r->print(' <font size="+1">'.
212: '<a href="/adm/coursegroups?action=modify&refpage=grouplist'.
213: '&state=pick_task&groupname='.$group.'">'.
214: &mt('Edit Group Settings').'</a></font>');
215: }
216: }
1.18 sakharuk 217: }
1.25 albertel 218: if (($env{'form.uploaddoc.filename'} and $target ne 'tex') &&
219: ($env{'form.storeupl'}) && ($allowed)) {
220: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.18 sakharuk 221: if ($syllabus{'uploaded.photourl'}) {
222: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
223: }
1.45 raeburn 224: if ($group ne '') {
1.28 raeburn 225: $syllabus{'uploaded.photourl'}=&Apache::lonnet::userfileupload(
1.45 raeburn 226: 'uploaddoc',1,"grouppage/$group");
1.28 raeburn 227: } else {
228: $syllabus{'uploaded.photourl'}=
229: &Apache::lonnet::userfileupload('uploaddoc',1,'simplepage');
230: }
1.18 sakharuk 231: }
232: $syllabus{'uploaded.lastmodified'}=time;
1.30 raeburn 233: &Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
1.18 sakharuk 234: }
1.25 albertel 235: if (($allowed) && ($env{'form.storesyl'})) {
1.48 albertel 236: foreach my $syl_field (keys(%syllabusfields)) {
237: my $field=$env{'form.'.$syl_field};
1.21 www 238: chomp($field);
1.18 sakharuk 239: $field=~s/\s+$//s;
1.21 www 240: $field=~s/^\s+//s;
241: $field=~s/\<br\s*\/*\>$//s;
1.18 sakharuk 242: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.48 albertel 243: $syllabus{$syl_field}=$field;
1.18 sakharuk 244: }
245: $syllabus{'uploaded.lastmodified'}=time;
1.30 raeburn 246: &Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
1.18 sakharuk 247: }
1.1 www 248:
249: # ---------------------------------------------------------------- Get syllabus
1.45 raeburn 250: if ((($syllabus{'uploaded.lastmodified'}) &&
1.46 raeburn 251: (($group ne '' && ($group_home_view || $group_edit_perm ||
252: $group_view_perm)) || ($group eq ''))) || ($allowed)) {
1.18 sakharuk 253: if ($syllabus{'uploaded.photourl'}) {
1.45 raeburn 254: &Apache::lonnet::allowuploaded('/adm/smppg',
1.19 sakharuk 255: $syllabus{'uploaded.photourl'});
1.20 albertel 256:
257: my $image='<img src="'.$syllabus{'uploaded.photourl'}.'"
258: align="right" />';
259: if ($target eq 'tex') {
260: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.18 sakharuk 261: }
1.20 albertel 262: $r->print($image);
1.18 sakharuk 263: }
264: if ($allowed) {
265: $r->print(
266: '<form method="post" enctype="multipart/form-data">'.
267: '<input type="hidden" name="forceedit" value="edit" />'.
268: '<h3>Upload a Photo</h3>'.
269: '<input type="file" name="uploaddoc" size="50">'.
270: '<input type="submit" name="storeupl" value="Upload">'.
271: '</form><form method="post">');
272: }
1.48 albertel 273: foreach my $field (sort(keys(%syllabusfields))) {
274: if (($syllabus{$field}) || ($allowed) ||
275: ($field eq 'abb_links' && $group ne '')) {
276: my $message=$syllabus{$field};
1.26 albertel 277: &Apache::lonfeedback::newline_to_br(\$message);
1.18 sakharuk 278: $message
279: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.22 www 280: if ($allowed) {
281: $message=&Apache::lonspeller::markeduptext($message);
282: }
1.27 www 283: $message=&Apache::lontexconvert::msgtexconverted($message);
1.48 albertel 284: if ($field eq 'abb_links' && $group ne '') {
285: $r->print('<br /><input type="hidden" name="'.$field.
286: '" value="'.$syllabus{$field}.'" />');
1.45 raeburn 287: &display_group_links($r,$target,$group,'edit',$refarg,
288: %groupinfo);
1.28 raeburn 289: $r->print('<br />');
1.48 albertel 290: } elsif ($field eq 'aaa_title') {
1.28 raeburn 291: if ($target ne 'tex') {
292: $r->print('<h1>'.$message.'</h1>');
293: } else {
294: my $safeinit;
295: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
296: }
297: if ($allowed) {
298: if ($env{'form.grade_target'} ne 'tex') {
299: $r->print(
1.48 albertel 300: '<br />Title<br /><textarea cols="80" rows="2" name="'.$field.'">'.
301: &HTML::Entities::encode($syllabus{$field},'"&<>').
1.28 raeburn 302: '</textarea><input type="submit" name="storesyl" value="Store" />');
303: } else {
304: my $safeinit;
1.48 albertel 305: $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$field},$safeinit));
1.28 raeburn 306: }
307: }
308: } else {
1.48 albertel 309: if (($field ne 'bbb_content') || ($allowed)) {
1.18 sakharuk 310: if ($target ne 'tex') {
1.48 albertel 311: $r->print('<h3>'.$syllabusfields{$field}.'</h3>');
1.18 sakharuk 312: } else {
313: my $safeinit;
1.48 albertel 314: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$field}.'</h3>'));
1.18 sakharuk 315: }
316: }
317: if ($target ne 'tex') {
318: $r->print('<blockquote>'.
319: $message.'</blockquote>');
1.14 sakharuk 320: } else {
321: my $safeinit;
1.18 sakharuk 322: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
323: }
324: if ($allowed) {
325: if ($target ne 'tex') {
1.48 albertel 326: $r->print('<br /><textarea cols="80" rows="24" name="'.$field.'" id="'.$field.'">'.
327: &HTML::Entities::encode($syllabus{$field},'"&<>').
1.18 sakharuk 328: '</textarea><input type="submit" name="storesyl" value="Store" />');
329: } else {
330: my $safeinit;
1.48 albertel 331: $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$field},$safeinit));
1.18 sakharuk 332: }
1.14 sakharuk 333: }
1.18 sakharuk 334: }
335: }
336: }
1.25 albertel 337: if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
1.21 www 338: $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
339: ('bbb_content').'</form>');
1.18 sakharuk 340: }
1.25 albertel 341: if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
1.1 www 342: } else {
1.45 raeburn 343: if ($group ne '') {
344: &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
345: } else {
346: $r->print(&mt('<p>No page information provided.</p>'));
347: }
1.1 www 348: }
1.25 albertel 349: if ($env{'form.grade_target'} ne 'tex') {
1.32 albertel 350: $r->print(&Apache::loncommon::end_page());
1.14 sakharuk 351: } else {
352: $r->print('\end{document}');
353: }
1.1 www 354: return OK;
1.28 raeburn 355: }
356:
357: sub display_group_links {
1.45 raeburn 358: my ($r,$target,$group,$context,$refarg,%groupinfo) = @_;
1.28 raeburn 359: my @available = ();
360: my %menu = ();
361: %{$menu{'email'}} = (
362: text => 'Group e-mail',
1.45 raeburn 363: href => '/adm/email?compose=group&group='.$group.
364: $refarg,
1.28 raeburn 365: );
366: %{$menu{'discussion'}} = (
367: text => 'Discussion Boards',
1.45 raeburn 368: href => '/adm/groupboards?group='.$group.$refarg,
1.28 raeburn 369: );
370: %{$menu{'chat'}} = (
371: text => 'Group chat',
1.45 raeburn 372: href => "javascript:group_chat('$group')",
1.28 raeburn 373: );
374: %{$menu{'files'}} = (
375: text => 'File repository',
1.45 raeburn 376: href => '/adm/coursegrp_portfolio?group='.$group.
377: $refarg,
1.28 raeburn 378: );
379: %{$menu{'roster'}} = (
380: text => 'Membership roster',
1.45 raeburn 381: href => '/adm/grouproster?group='.$group.$refarg,
1.28 raeburn 382: );
383: foreach my $tool (sort(keys(%menu))) {
384: if ($groupinfo{functions}{$tool} eq 'on') {
385: push(@available,$tool);
386: }
387: }
388: if (@available > 0) {
389: my $output = '<table cellspacing="4" cellpadding="4"><tr>';
390: foreach my $tool (@available) {
391: if ($target eq 'tex') {
1.45 raeburn 392: $output .= '<td>'.&mt($menu{$tool}{text}).'</td>';
1.28 raeburn 393: } else {
394: $output .= '<td><a href="'.$menu{$tool}{href}.'">'.
395: $menu{$tool}{text}.'</a></td>';
396: }
397: }
398: $output .= '</tr></table>';
399: if ($target eq 'tex') {
1.45 raeburn 400: $r->print(&Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'<br /><br />'.$output));
1.28 raeburn 401: } else {
1.45 raeburn 402: $r->print('<h3>'.&mt('Available Group Tools').'</h3>'.$output);
1.28 raeburn 403: }
404: } else {
1.29 raeburn 405: my $output;
406: if ($context eq 'edit') {
1.45 raeburn 407: $output = &mt('No group functionality.');
1.29 raeburn 408: } else {
1.45 raeburn 409: $output = &mt('No group functionality (e.g., e-mail, discussion, chat or file upload) is currently available to you in this group: <b>[_1]</b>.',&unescape($groupinfo{'description'}));
1.29 raeburn 410: }
1.28 raeburn 411: if ($target eq 'tex') {
412: $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
413: } else {
414: $r->print($output);
415: }
416: }
417: }
1.44 raeburn 418:
419: sub grouppage_breadcrumbs {
1.45 raeburn 420: my ($cdom,$cnum,$group,$description) = @_;
1.44 raeburn 421: &Apache::lonhtmlcommon::clear_breadcrumbs();
422: &Apache::lonhtmlcommon::add_breadcrumb
423: ({href=>"/adm/coursegroups",
1.45 raeburn 424: text=>"Groups",
425: title=>"Display Groups"},
1.44 raeburn 426: {href=>"/adm/$cdom/$cnum/$group/smppg?ref=grouplist",
1.45 raeburn 427: text=>"Group: $description",
1.44 raeburn 428: title=>"Go to group's home page"},
429: );
1.45 raeburn 430: my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group page - [_1]',
431: $description));
1.44 raeburn 432: return $output;
433: }
1.1 www 434:
435: 1;
436: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>