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