Annotation of loncom/interface/lonsimplepage.pm, revision 1.46
1.1 www 1: # The LearningOnline Network
2: # Simple Page Editor
3: #
1.46 ! raeburn 4: # $Id: lonsimplepage.pm,v 1.45 2006/07/20 03:11:52 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; }
1.46 ! raeburn 185:
1.18 sakharuk 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'}) &&
1.46 ! raeburn 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) {
1.46 ! raeburn 261: if (($syllabus{$_}) || ($allowed) ||
! 262: ($_ eq 'abb_links' && $group ne '')) {
1.18 sakharuk 263: my $message=$syllabus{$_};
1.26 albertel 264: &Apache::lonfeedback::newline_to_br(\$message);
1.18 sakharuk 265: $message
266: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.22 www 267: if ($allowed) {
268: $message=&Apache::lonspeller::markeduptext($message);
269: }
1.27 www 270: $message=&Apache::lontexconvert::msgtexconverted($message);
1.43 raeburn 271: if ($_ eq 'abb_links' && $group ne '') {
1.28 raeburn 272: $r->print('<br /><input type="hidden" name="'.$_.
273: '" value="'.$syllabus{$_}.'" />');
1.45 raeburn 274: &display_group_links($r,$target,$group,'edit',$refarg,
275: %groupinfo);
1.28 raeburn 276: $r->print('<br />');
277: } elsif ($_ eq 'aaa_title') {
278: if ($target ne 'tex') {
279: $r->print('<h1>'.$message.'</h1>');
280: } else {
281: my $safeinit;
282: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
283: }
284: if ($allowed) {
285: if ($env{'form.grade_target'} ne 'tex') {
286: $r->print(
287: '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
288: $syllabus{$_}.
289: '</textarea><input type="submit" name="storesyl" value="Store" />');
290: } else {
291: my $safeinit;
292: $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
293: }
294: }
295: } else {
1.18 sakharuk 296: if (($_ ne 'bbb_content') || ($allowed)) {
297: if ($target ne 'tex') {
298: $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
299: } else {
300: my $safeinit;
301: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$_}.'</h3>'));
302: }
303: }
304: if ($target ne 'tex') {
305: $r->print('<blockquote>'.
306: $message.'</blockquote>');
1.14 sakharuk 307: } else {
308: my $safeinit;
1.18 sakharuk 309: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
310: }
311: if ($allowed) {
312: if ($target ne 'tex') {
1.21 www 313: $r->print('<br /><textarea cols="80" rows="24" name="'.$_.'" id="'.$_.'">'.
1.18 sakharuk 314: $syllabus{$_}.
315: '</textarea><input type="submit" name="storesyl" value="Store" />');
316: } else {
317: my $safeinit;
318: $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
319: }
1.14 sakharuk 320: }
1.18 sakharuk 321: }
322: }
323: }
1.25 albertel 324: if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
1.21 www 325: $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
326: ('bbb_content').'</form>');
1.18 sakharuk 327: }
1.25 albertel 328: if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
1.1 www 329: } else {
1.45 raeburn 330: if ($group ne '') {
331: &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
332: } else {
333: $r->print(&mt('<p>No page information provided.</p>'));
334: }
1.1 www 335: }
1.25 albertel 336: if ($env{'form.grade_target'} ne 'tex') {
1.32 albertel 337: $r->print(&Apache::loncommon::end_page());
1.14 sakharuk 338: } else {
339: $r->print('\end{document}');
340: }
1.1 www 341: return OK;
1.28 raeburn 342: }
343:
344: sub display_group_links {
1.45 raeburn 345: my ($r,$target,$group,$context,$refarg,%groupinfo) = @_;
1.28 raeburn 346: my @available = ();
347: my %menu = ();
348: %{$menu{'email'}} = (
349: text => 'Group e-mail',
1.45 raeburn 350: href => '/adm/email?compose=group&group='.$group.
351: $refarg,
1.28 raeburn 352: );
353: %{$menu{'discussion'}} = (
354: text => 'Discussion Boards',
1.45 raeburn 355: href => '/adm/groupboards?group='.$group.$refarg,
1.28 raeburn 356: );
357: %{$menu{'chat'}} = (
358: text => 'Group chat',
1.45 raeburn 359: href => "javascript:group_chat('$group')",
1.28 raeburn 360: );
361: %{$menu{'files'}} = (
362: text => 'File repository',
1.45 raeburn 363: href => '/adm/coursegrp_portfolio?group='.$group.
364: $refarg,
1.28 raeburn 365: );
366: %{$menu{'roster'}} = (
367: text => 'Membership roster',
1.45 raeburn 368: href => '/adm/grouproster?group='.$group.$refarg,
1.28 raeburn 369: );
370: foreach my $tool (sort(keys(%menu))) {
371: if ($groupinfo{functions}{$tool} eq 'on') {
372: push(@available,$tool);
373: }
374: }
375: if (@available > 0) {
376: my $output = '<table cellspacing="4" cellpadding="4"><tr>';
377: foreach my $tool (@available) {
378: if ($target eq 'tex') {
1.45 raeburn 379: $output .= '<td>'.&mt($menu{$tool}{text}).'</td>';
1.28 raeburn 380: } else {
381: $output .= '<td><a href="'.$menu{$tool}{href}.'">'.
382: $menu{$tool}{text}.'</a></td>';
383: }
384: }
385: $output .= '</tr></table>';
386: if ($target eq 'tex') {
1.45 raeburn 387: $r->print(&Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'<br /><br />'.$output));
1.28 raeburn 388: } else {
1.45 raeburn 389: $r->print('<h3>'.&mt('Available Group Tools').'</h3>'.$output);
1.28 raeburn 390: }
391: } else {
1.29 raeburn 392: my $output;
393: if ($context eq 'edit') {
1.45 raeburn 394: $output = &mt('No group functionality.');
1.29 raeburn 395: } else {
1.45 raeburn 396: $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 397: }
1.28 raeburn 398: if ($target eq 'tex') {
399: $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
400: } else {
401: $r->print($output);
402: }
403: }
404: }
1.44 raeburn 405:
406: sub grouppage_breadcrumbs {
1.45 raeburn 407: my ($cdom,$cnum,$group,$description) = @_;
1.44 raeburn 408: &Apache::lonhtmlcommon::clear_breadcrumbs();
409: &Apache::lonhtmlcommon::add_breadcrumb
410: ({href=>"/adm/coursegroups",
1.45 raeburn 411: text=>"Groups",
412: title=>"Display Groups"},
1.44 raeburn 413: {href=>"/adm/$cdom/$cnum/$group/smppg?ref=grouplist",
1.45 raeburn 414: text=>"Group: $description",
1.44 raeburn 415: title=>"Go to group's home page"},
416: );
1.45 raeburn 417: my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group page - [_1]',
418: $description));
1.44 raeburn 419: return $output;
420: }
1.1 www 421:
422: 1;
423: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>