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