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