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