Annotation of loncom/interface/lonsimplepage.pm, revision 1.47
1.1 www 1: # The LearningOnline Network
2: # Simple Page Editor
3: #
1.47 ! albertel 4: # $Id: lonsimplepage.pm,v 1.46 2006/07/20 15:03:01 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.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) &&
153: (!$group_view_perm) && (!$group_edit_perm)) {
154: &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
1.28 raeburn 155: return OK;
156: }
157: } else {
1.35 albertel 158: my $msg =
159: &mt('You do not currently have rights to view this group.');
1.28 raeburn 160: if ($target ne 'tex') {
1.35 albertel 161: $r->print("<p>$msg</p>".
1.32 albertel 162: &Apache::loncommon::end_page());
1.28 raeburn 163: } else {
1.35 albertel 164: $r->print('\textbf{'.$msg.'}\end{document}');
1.28 raeburn 165: }
1.35 albertel 166: return OK;
1.28 raeburn 167: }
1.14 sakharuk 168: }
1.1 www 169:
1.28 raeburn 170: my $allowed;
1.45 raeburn 171:
1.43 raeburn 172: if ($group ne '') {
1.45 raeburn 173: $allowed = $group_edit_perm;
1.42 raeburn 174: if (!$allowed) {
1.45 raeburn 175: $allowed = $group_home_edit;
1.28 raeburn 176: }
177: } else {
178: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
179: }
1.16 www 180: my $privileged=$allowed;
181: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
182: $forcestudent='student';
183: }
1.1 www 184:
1.18 sakharuk 185: if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.46 raeburn 186:
1.18 sakharuk 187: if ($allowed) {
188: $r->print('<p>'.
1.45 raeburn 189: &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 190: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
191: } elsif ($privileged and $target ne 'tex') {
1.45 raeburn 192: my $edittext = &mt('Edit');
193: if ($group ne '') {
194: $edittext = &mt('Edit Group Homepage');
195: }
196: $r->print('<a href="'.$r->uri.'?forceedit=edit'.$refarg.'"><font size="+1">'.$edittext.'</font></a>');
197: if ($group ne '') {
198: if ($group_edit_perm) {
199: $r->print(' <font size="+1">'.
200: '<a href="/adm/coursegroups?action=modify&refpage=grouplist'.
201: '&state=pick_task&groupname='.$group.'">'.
202: &mt('Edit Group Settings').'</a></font>');
203: }
204: }
1.18 sakharuk 205: }
1.25 albertel 206: if (($env{'form.uploaddoc.filename'} and $target ne 'tex') &&
207: ($env{'form.storeupl'}) && ($allowed)) {
208: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.18 sakharuk 209: if ($syllabus{'uploaded.photourl'}) {
210: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
211: }
1.45 raeburn 212: if ($group ne '') {
1.28 raeburn 213: $syllabus{'uploaded.photourl'}=&Apache::lonnet::userfileupload(
1.45 raeburn 214: 'uploaddoc',1,"grouppage/$group");
1.28 raeburn 215: } else {
216: $syllabus{'uploaded.photourl'}=
217: &Apache::lonnet::userfileupload('uploaddoc',1,'simplepage');
218: }
1.18 sakharuk 219: }
220: $syllabus{'uploaded.lastmodified'}=time;
1.30 raeburn 221: &Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
1.18 sakharuk 222: }
1.25 albertel 223: if (($allowed) && ($env{'form.storesyl'})) {
1.18 sakharuk 224: foreach (keys %syllabusfields) {
1.25 albertel 225: my $field=$env{'form.'.$_};
1.21 www 226: chomp($field);
1.18 sakharuk 227: $field=~s/\s+$//s;
1.21 www 228: $field=~s/^\s+//s;
229: $field=~s/\<br\s*\/*\>$//s;
1.18 sakharuk 230: $field=&Apache::lonfeedback::clear_out_html($field,1);
231: $syllabus{$_}=$field;
232: }
233: $syllabus{'uploaded.lastmodified'}=time;
1.30 raeburn 234: &Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
1.18 sakharuk 235: }
1.1 www 236:
237: # ---------------------------------------------------------------- Get syllabus
1.45 raeburn 238: if ((($syllabus{'uploaded.lastmodified'}) &&
1.46 raeburn 239: (($group ne '' && ($group_home_view || $group_edit_perm ||
240: $group_view_perm)) || ($group eq ''))) || ($allowed)) {
1.18 sakharuk 241: if ($syllabus{'uploaded.photourl'}) {
1.45 raeburn 242: &Apache::lonnet::allowuploaded('/adm/smppg',
1.19 sakharuk 243: $syllabus{'uploaded.photourl'});
1.20 albertel 244:
245: my $image='<img src="'.$syllabus{'uploaded.photourl'}.'"
246: align="right" />';
247: if ($target eq 'tex') {
248: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.18 sakharuk 249: }
1.20 albertel 250: $r->print($image);
1.18 sakharuk 251: }
252: if ($allowed) {
253: $r->print(
254: '<form method="post" enctype="multipart/form-data">'.
255: '<input type="hidden" name="forceedit" value="edit" />'.
256: '<h3>Upload a Photo</h3>'.
257: '<input type="file" name="uploaddoc" size="50">'.
258: '<input type="submit" name="storeupl" value="Upload">'.
259: '</form><form method="post">');
260: }
261: foreach (sort keys %syllabusfields) {
1.46 raeburn 262: if (($syllabus{$_}) || ($allowed) ||
263: ($_ eq 'abb_links' && $group ne '')) {
1.18 sakharuk 264: my $message=$syllabus{$_};
1.26 albertel 265: &Apache::lonfeedback::newline_to_br(\$message);
1.18 sakharuk 266: $message
267: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.22 www 268: if ($allowed) {
269: $message=&Apache::lonspeller::markeduptext($message);
270: }
1.27 www 271: $message=&Apache::lontexconvert::msgtexconverted($message);
1.43 raeburn 272: if ($_ eq 'abb_links' && $group ne '') {
1.28 raeburn 273: $r->print('<br /><input type="hidden" name="'.$_.
274: '" value="'.$syllabus{$_}.'" />');
1.45 raeburn 275: &display_group_links($r,$target,$group,'edit',$refarg,
276: %groupinfo);
1.28 raeburn 277: $r->print('<br />');
278: } elsif ($_ eq 'aaa_title') {
279: if ($target ne 'tex') {
280: $r->print('<h1>'.$message.'</h1>');
281: } else {
282: my $safeinit;
283: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
284: }
285: if ($allowed) {
286: if ($env{'form.grade_target'} ne 'tex') {
287: $r->print(
288: '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
1.47 ! albertel 289: &HTML::Entities::encode($syllabus{$_},'"&<>').
1.28 raeburn 290: '</textarea><input type="submit" name="storesyl" value="Store" />');
291: } else {
292: my $safeinit;
293: $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
294: }
295: }
296: } else {
1.18 sakharuk 297: if (($_ ne 'bbb_content') || ($allowed)) {
298: if ($target ne 'tex') {
299: $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
300: } else {
301: my $safeinit;
302: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$_}.'</h3>'));
303: }
304: }
305: if ($target ne 'tex') {
306: $r->print('<blockquote>'.
307: $message.'</blockquote>');
1.14 sakharuk 308: } else {
309: my $safeinit;
1.18 sakharuk 310: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
311: }
312: if ($allowed) {
313: if ($target ne 'tex') {
1.21 www 314: $r->print('<br /><textarea cols="80" rows="24" name="'.$_.'" id="'.$_.'">'.
1.47 ! albertel 315: &HTML::Entities::encode($syllabus{$_},'"&<>').
1.18 sakharuk 316: '</textarea><input type="submit" name="storesyl" value="Store" />');
317: } else {
318: my $safeinit;
319: $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
320: }
1.14 sakharuk 321: }
1.18 sakharuk 322: }
323: }
324: }
1.25 albertel 325: if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
1.21 www 326: $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
327: ('bbb_content').'</form>');
1.18 sakharuk 328: }
1.25 albertel 329: if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
1.1 www 330: } else {
1.45 raeburn 331: if ($group ne '') {
332: &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
333: } else {
334: $r->print(&mt('<p>No page information provided.</p>'));
335: }
1.1 www 336: }
1.25 albertel 337: if ($env{'form.grade_target'} ne 'tex') {
1.32 albertel 338: $r->print(&Apache::loncommon::end_page());
1.14 sakharuk 339: } else {
340: $r->print('\end{document}');
341: }
1.1 www 342: return OK;
1.28 raeburn 343: }
344:
345: sub display_group_links {
1.45 raeburn 346: my ($r,$target,$group,$context,$refarg,%groupinfo) = @_;
1.28 raeburn 347: my @available = ();
348: my %menu = ();
349: %{$menu{'email'}} = (
350: text => 'Group e-mail',
1.45 raeburn 351: href => '/adm/email?compose=group&group='.$group.
352: $refarg,
1.28 raeburn 353: );
354: %{$menu{'discussion'}} = (
355: text => 'Discussion Boards',
1.45 raeburn 356: href => '/adm/groupboards?group='.$group.$refarg,
1.28 raeburn 357: );
358: %{$menu{'chat'}} = (
359: text => 'Group chat',
1.45 raeburn 360: href => "javascript:group_chat('$group')",
1.28 raeburn 361: );
362: %{$menu{'files'}} = (
363: text => 'File repository',
1.45 raeburn 364: href => '/adm/coursegrp_portfolio?group='.$group.
365: $refarg,
1.28 raeburn 366: );
367: %{$menu{'roster'}} = (
368: text => 'Membership roster',
1.45 raeburn 369: href => '/adm/grouproster?group='.$group.$refarg,
1.28 raeburn 370: );
371: foreach my $tool (sort(keys(%menu))) {
372: if ($groupinfo{functions}{$tool} eq 'on') {
373: push(@available,$tool);
374: }
375: }
376: if (@available > 0) {
377: my $output = '<table cellspacing="4" cellpadding="4"><tr>';
378: foreach my $tool (@available) {
379: if ($target eq 'tex') {
1.45 raeburn 380: $output .= '<td>'.&mt($menu{$tool}{text}).'</td>';
1.28 raeburn 381: } else {
382: $output .= '<td><a href="'.$menu{$tool}{href}.'">'.
383: $menu{$tool}{text}.'</a></td>';
384: }
385: }
386: $output .= '</tr></table>';
387: if ($target eq 'tex') {
1.45 raeburn 388: $r->print(&Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'<br /><br />'.$output));
1.28 raeburn 389: } else {
1.45 raeburn 390: $r->print('<h3>'.&mt('Available Group Tools').'</h3>'.$output);
1.28 raeburn 391: }
392: } else {
1.29 raeburn 393: my $output;
394: if ($context eq 'edit') {
1.45 raeburn 395: $output = &mt('No group functionality.');
1.29 raeburn 396: } else {
1.45 raeburn 397: $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 398: }
1.28 raeburn 399: if ($target eq 'tex') {
400: $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
401: } else {
402: $r->print($output);
403: }
404: }
405: }
1.44 raeburn 406:
407: sub grouppage_breadcrumbs {
1.45 raeburn 408: my ($cdom,$cnum,$group,$description) = @_;
1.44 raeburn 409: &Apache::lonhtmlcommon::clear_breadcrumbs();
410: &Apache::lonhtmlcommon::add_breadcrumb
411: ({href=>"/adm/coursegroups",
1.45 raeburn 412: text=>"Groups",
413: title=>"Display Groups"},
1.44 raeburn 414: {href=>"/adm/$cdom/$cnum/$group/smppg?ref=grouplist",
1.45 raeburn 415: text=>"Group: $description",
1.44 raeburn 416: title=>"Go to group's home page"},
417: );
1.45 raeburn 418: my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group page - [_1]',
419: $description));
1.44 raeburn 420: return $output;
421: }
1.1 www 422:
423: 1;
424: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>