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