Annotation of loncom/interface/lonaboutme.pm, revision 1.72

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.72    ! amueller    4: # $Id: lonaboutme.pm,v 1.71 2008/11/11 10:45:22 amueller 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::lonaboutme;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::loncommon;
                     34: use Apache::lonnet;
1.2       www        35: use Apache::lontexconvert;
1.12      www        36: use Apache::lonfeedback;
1.39      www        37: use Apache::lonrss();
1.17      www        38: use Apache::lonlocal;
1.41      albertel   39: use Apache::lonmsgdisplay();
1.72    ! amueller   40: use Apache::lontemplate;
1.52      albertel   41: use HTML::Entities();
1.1       www        42: 
                     43: sub handler {
                     44:     my $r = shift;
1.17      www        45:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        46:     $r->send_http_header;
                     47:     return OK if $r->header_only;
1.37      albertel   48:     my $target=$env{'form.grade_target'};
1.1       www        49: # ------------------------------------------------------------ Print the screen
1.40      albertel   50:     if ($target eq 'tex') {
1.37      albertel   51: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.22      sakharuk   52:     }
1.47      albertel   53:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
1.55      raeburn    54:     my $is_course;
1.2       www        55: # Is this even a user?
                     56:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
1.40      albertel   57: 	&Apache::loncommon::simple_error_page($r,'No info',
                     58: 					      'No user information available');
1.2       www        59:         return OK;
1.55      raeburn    60:     } else {
1.59      raeburn    61:         $is_course = &Apache::lonnet::is_course($cdom,$cnum);
1.2       www        62:     }
1.55      raeburn    63: 
1.2       www        64: # --------------------------------------------------------- The syllabus fields
1.17      www        65:     my %syllabusfields=&Apache::lonlocal::texthash(
1.3       www        66:        'aaa_contactinfo'   => 'Contact Information',
                     67:        'bbb_aboutme'       => 'About Me',
                     68:        'ccc_webreferences' => 'Web References');
1.2       www        69: 
1.13      www        70: # ------------------------------------------------------------ Get Query String
1.47      albertel   71:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     72: 					    ['forceedit','forcestudent',
1.69      raeburn    73: 					     'register','popup']);
1.43      raeburn    74: 
                     75: # ----------------------------------------------- Available Portfolio file display 
1.47      albertel   76:     if (($target ne 'tex') && ($action eq 'portfolio')) {
1.55      raeburn    77:         &display_portfolio_header($r,$is_course);
1.60      raeburn    78:         my ($blocked,$blocktext) = 
                     79:            &Apache::loncommon::blocking_status('port',$cnum,$cdom);
                     80:         if (!$blocked) {
                     81:             &display_portfolio_files($r,$is_course);
                     82:         } else {
                     83:             $r->print($blocktext);
                     84:         }
1.43      raeburn    85:         $r->print(&Apache::loncommon::end_page());
                     86:         return OK;
                     87:     }
                     88: 
1.55      raeburn    89:     if ($is_course) {
                     90:         if ($target ne 'tex') {
                     91:             my $start_page =
                     92:                 &Apache::loncommon::start_page(
                     93:                     "Course Information",
                     94:                      undef,
                     95:                      {'function' => $env{'forcestudent'},
                     96:                       'domain'   => $cdom,
                     97:                       'force_register' => $env{'forceregister'},});
                     98:             $r->print($start_page);
                     99:             $r->print('<h2>'.&mt('Group files').'</h2>');
                    100:             &print_portfiles_link($r,$is_course);
                    101:             $r->print(&Apache::loncommon::end_page());
                    102:         }
                    103:         return OK;
                    104:     }
                    105: 
1.2       www       106: # --------------------------------------------------------------- Force Student
                    107:     my $forcestudent='';
1.37      albertel  108:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.43      raeburn   109: 
                    110:     my $forceregister = '';
                    111:     if ($forcestudent eq '') {
                    112:         $forceregister = $env{'form.register'};
                    113:     }
1.2       www       114:        
                    115: # --------------------------------------- There is such a user, get environment
                    116:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.22      sakharuk  117:     if ($target ne 'tex') {
1.65      albertel  118: 	my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.69      raeburn   119:         my $args = {'function' => $forcestudent,
                    120:                     'domain'   => $cdom,
                    121:                     'force_register' => $forceregister};
                    122:         if ($env{'form.popup'}) {
                    123:             $args->{'no_nav_bar'} = 1;
                    124:         }
1.40      albertel  125: 	my $start_page = 
1.69      raeburn   126: 	    &Apache::loncommon::start_page("Personal Information",$rss_link,$args);
1.40      albertel  127: 	$r->print($start_page);
1.22      sakharuk  128: 	$r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
                    129:     } else {
                    130: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
                    131:     }
1.6       www       132:     if ($courseenv{'nickname'}) {
                    133:        $r->print(
1.7       albertel  134:          '<h2>&quot;'.$courseenv{'nickname'}.
1.6       www       135:          '&quot;</h2>');
                    136:     }
1.22      sakharuk  137:     if ($target ne 'tex') {
1.71      amueller  138: 	$r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');#OLD SendMessage POS
1.22      sakharuk  139:     } else {
1.61      albertel  140: 	$r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
1.22      sakharuk  141:     }
1.2       www       142:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
                    143:     my $allowed=0;
                    144: 
1.1       www       145: # does this user have privileges to post, etc?
1.2       www       146: 
1.37      albertel  147:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
                    148: 			       ($env{'user.domain'} eq $cdom));
1.23      sakharuk  149:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2       www       150:  
                    151:        if ($allowed) {
1.69      raeburn   152:            my $query_string = &build_query_string({'forcestudent' => '1','popup' => $env{'form.popup'}});
1.32      albertel  153: 	   $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
                    154: 		     &mt('The information you submit can be viewed by anybody who is logged into LON-CAPA. Do not provide information that you are not ready to share publicly.').
                    155: 		     '</p>'.
1.67      bisitz    156: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p><p><a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.
1.32      albertel  157: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
                    158:        } elsif ($privleged && $target ne 'tex') {
1.69      raeburn   159:            my $query_string = &build_query_string({'forceedit' => '1','popup' => $env{'form.popup'}});
1.43      raeburn   160: 	   $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
1.32      albertel  161: 		     &mt('Edit').'</font></a></p>');
                    162:        }
1.37      albertel  163:       if (($env{'form.uploaddoc.filename'}) &&
                    164:           ($env{'form.storeupl'}) && ($allowed)) {
                    165:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.24      albertel  166: 	      if ($syllabus{'uploaded.photourl'}) {
                    167: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    168: 	      }
                    169: 	      $syllabus{'uploaded.photourl'}=
                    170:                  &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
1.3       www       171:  	  }
                    172:           $syllabus{'uploaded.lastmodified'}=time;
                    173:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    174:        }
1.37      albertel  175:     if ($allowed && $env{'form.delupl'}) {
1.32      albertel  176: 	if ($syllabus{'uploaded.photourl'}) {
                    177: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    178: 	    delete($syllabus{'uploaded.photourl'});
                    179: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
                    180: 	}
                    181:     }
1.37      albertel  182:        if (($allowed) && ($env{'form.storesyl'})) {
1.57      albertel  183: 	   foreach my $syl_field (keys(%syllabusfields)) {
                    184:                my $field=$env{'form.'.$syl_field};
1.2       www       185:                $field=~s/\s+$//s;
1.11      www       186:                $field=&Apache::lonfeedback::clear_out_html($field,
1.37      albertel  187:                                                            $env{'user.adv'});
1.57      albertel  188: 	       $syllabus{$syl_field}=$field;
1.2       www       189:            }
                    190:            $syllabus{'uploaded.lastmodified'}=time;
                    191:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    192:        }
                    193: 
1.71      amueller  194: my $lastmod;
                    195: my $image; 
1.2       www       196: # ---------------------------------------------------------------- Get syllabus
                    197:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.71      amueller  198:        $lastmod=$syllabus{'uploaded.lastmodified'};
1.18      www       199:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.71      amueller  200:        # $r->print(&mt('Last updated').': '.$lastmod); #Old Last Modifi Pos
1.3       www       201:        if ($syllabus{'uploaded.photourl'}) {
1.24      albertel  202: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
                    203: 					  $syllabus{'uploaded.photourl'});
1.71      amueller  204: 	   $image=
                    205:                qq{<img src="$syllabus{'uploaded.photourl'}" style="vertical-align:text-top;float:right;" />};
1.27      albertel  206: 	   if ($target eq 'tex') {
                    207: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.26      sakharuk  208: 	   }
1.71      amueller  209: 	  # $r->print($image); #Print old Image
1.3       www       210:        }
1.23      sakharuk  211:        if ($allowed) {
1.3       www       212:            $r->print(
1.32      albertel  213: 	 '<form method="post">
1.66      bisitz    214:                <input type="submit" name="delupl" value="'.&mt('Delete Photo').'" />
1.32      albertel  215:           </form>'.
1.3       www       216: 	 '<form method="post" enctype="multipart/form-data">'.
1.18      www       217:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.68      raeburn   218:          '<input type="file" name="uploaddoc" size="50" />'.
                    219:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
1.69      raeburn   220:          '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
1.3       www       221: 	 '</form><form method="post">');
1.32      albertel  222: 
1.2       www       223:        }
1.71      amueller  224: 
                    225: 	
1.57      albertel  226:        foreach my $field (sort(keys(%syllabusfields))) {
                    227:           if (($syllabus{$field}) || ($allowed)) {
                    228:               my $message=$syllabus{$field};
1.38      albertel  229: 	      &Apache::lonfeedback::newline_to_br(\$message);
1.2       www       230:               $message
                    231:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.29      www       232: 	      if ($allowed) {
                    233: 		  $message=&Apache::lonspeller::markeduptext($message);
                    234: 	      }
1.2       www       235: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.22      sakharuk  236: 	      if ($target ne 'tex') {
1.72    ! amueller  237: 				
        !           238: 		Apache::lontemplate::print_template($r,$syllabusfields{$field},$message);
        !           239: 				
        !           240: 				
        !           241: 				
1.22      sakharuk  242: 	      } else {
1.57      albertel  243: 		     $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
1.25      sakharuk  244: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.22      sakharuk  245: 	      }
1.23      sakharuk  246:               if ($allowed) {
1.72    ! amueller  247: 		Apache::lontemplate::print_editbox_template($r,$syllabusfields{$field},$field);
1.2       www       248: 	      }
                    249: 	  }
                    250:        }
1.71      amueller  251:        if($target ne 'tex')
                    252:        {
                    253: 		
1.72    ! amueller  254: 		  &print_portfiles_link($r,$is_course);
1.71      amueller  255:  
                    256:       		 $r->print('</div>');
                    257: 			$r->print('<div style="margin:0 0 0 75">');
                    258:         $r->print($image);
                    259: 
                    260: 	$r->print('Kontakt');
                    261: 	$r->print(&Apache::loncommon::messagewrapper(&mt('Send me a message'),$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
                    262: 
                    263: 
                    264:        }
                    265: 
1.23      sakharuk  266:        if ($allowed) {
1.69      raeburn   267:            if ($env{'form.popup'}) {
                    268:                $r->print('<input type="hidden" name="popup" value="'.
                    269:                          $env{'form.popup'}.'" />');
                    270:            }
1.2       www       271: 	   $r->print('</form>');
                    272:        }
1.46      albertel  273:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2       www       274:     } else {
1.17      www       275:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8       www       276:     }
1.43      raeburn   277: 
                    278:     if ($target ne 'tex') {
1.71      amueller  279:         # &print_portfiles_link($r,$is_course); #old Print files
                    280: 
1.43      raeburn   281:     }
                    282: 
1.63      albertel  283:     if ($env{'request.course.id'}
                    284: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    285: 	&& &in_course($cdom,$cnum)) {
                    286: 	if ($target ne 'tex') {
                    287: 	    $r->print('<a name="coursecomment" />');
                    288: 	    $r->print('<hr /><h3>'.
                    289: 		      &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
                    290: 		      &mt('Shared by course faculty and staff').
                    291: 		      &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
                    292: 		      '<br />');
                    293: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    294: 	    $r->print('<hr />');
                    295: 	    if (&Apache::lonnet::allowed('vsa',
                    296: 					 $env{'request.course.id'}) ||
                    297: 		&Apache::lonnet::allowed('vsa',
                    298: 					 $env{'request.course.id'}.'/'.
                    299: 					 $env{'request.course.sec'})) {
                    300: 		$r->print(&Apache::loncommon::track_student_link
                    301: 			  ('View recent activity by this student',
                    302: 			   $cnum,$cdom).('&nbsp;'x2));
1.22      sakharuk  303: 	    }
1.63      albertel  304: 	    $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
                    305: 	} else {
                    306: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
                    307: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    308: 	}
1.1       www       309:     }
1.40      albertel  310:     if ($target ne 'tex') {
1.69      raeburn   311:         if ($env{'form.popup'}) {
                    312:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
                    313:         }
1.71      amueller  314: 	$r->print('<br />'.&mt('Last updated').': '.$lastmod);
                    315: 
1.40      albertel  316: 	$r->print(&Apache::loncommon::end_page());
                    317:     } else {
                    318: 	$r->print('\end{document}');
                    319:     }
1.71      amueller  320: 
                    321:   
                    322: 	
1.1       www       323:     return OK;
1.43      raeburn   324: }
                    325: 
1.63      albertel  326: sub in_course {
                    327:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
                    328:     $type ||= 'any';
                    329:     if (!defined($cdom) || !defined($cnum)) {
                    330: 	my $cid  = $env{'request.course.id'};
                    331: 	$cdom = $env{'course.'.$cid.'.domain'};
                    332: 	$cnum = $env{'course.'.$cid.'.num'};
                    333:     }
                    334:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
                    335:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
                    336:     return 0 if (!@course_roles);
                    337:     return 1 if ($type eq 'any');
                    338:     my $now = time();
                    339:     foreach my $role (@course_roles) {
                    340: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
                    341: 	my $status = 'active';
                    342: 	if ($role_start > 0 && $now < $role_start) {
                    343: 	    $status = 'future';
                    344: 	}
                    345: 	if ($role_end > 0 && $now > $role_end) {
                    346: 	    $status = 'previous';
                    347: 	}
                    348: 	return 1 if ($status eq $type);
                    349:     }
                    350:     return 0;
                    351: }
                    352: 
1.43      raeburn   353: sub aboutme_info {
1.55      raeburn   354:     my ($r,$is_course) = @_;
1.43      raeburn   355:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55      raeburn   356:     my $name;
                    357:     if (!$is_course) {
                    358:         $name = &Apache::loncommon::plainname($cnum,$cdom);
                    359:     }
1.43      raeburn   360:     return ($cdom,$cnum,$name);
                    361: }
                    362: 
                    363: sub print_portfiles_link {
1.55      raeburn   364:     my ($r,$is_course) = @_;
                    365:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.64      raeburn   366:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
                    367:                                       $cdom,$cnum,$name);
1.47      albertel  368:     my $query_string = &build_query_string();
1.43      raeburn   369:     my $output;
1.55      raeburn   370:     my %lt = &Apache::lonlocal::texthash(
                    371:                          vpfi => 'Viewable portfolio files',
                    372:                          vgpf => 'Viewable group portfolio files',
                    373:                          difl => 'Display file listing',
                    374:              );                     
1.43      raeburn   375:     if ($filecounts->{'both'} > 0) {
1.71      amueller  376: 	$output = '<fieldset><legend><b>';
                    377: 	$output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</b></legend><br />';
                    378:         
                    379: 	#$output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
1.47      albertel  380:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55      raeburn   381:                    $query_string.'">'.$lt{'difl'}.
1.43      raeburn   382:                    '</a><br /><br />';
1.53      raeburn   383:         if ($filecounts->{'both'} == 1) {
1.55      raeburn   384:             if ($is_course) {
                    385:                 $output .= &mt('One group portfolio file is available.').'<ul>';
                    386:             } else {
1.56      albertel  387:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55      raeburn   388:             }
1.53      raeburn   389:         } else {
1.55      raeburn   390:             if ($is_course) {
1.56      albertel  391:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55      raeburn   392:             } else {
                    393:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
                    394:             }
1.53      raeburn   395:         }
1.43      raeburn   396:         if ($filecounts->{'withoutpass'}) {
1.54      albertel  397: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43      raeburn   398:         }
                    399:         if ($filecounts->{'withpass'}) {
1.54      albertel  400: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   401:         }
                    402:         $output .= '</ul>';
1.71      amueller  403: 	$output .='</fieldset>';
1.43      raeburn   404:     }
                    405:     $r->print($output);
                    406:     return;
                    407: }
                    408: 
                    409: sub build_query_string {
                    410:     my ($new_items) = @_;
                    411:     my $query_string;
                    412:     my @formelements = ('register'); 
1.47      albertel  413:     my $new = 0;
1.43      raeburn   414:     if (ref($new_items) eq 'HASH') {
1.47      albertel  415:         $new = 1;
1.43      raeburn   416:         if (!defined($new_items->{'forceedit'}) && 
                    417:             !defined($new_items->{'forcestudent'})) {
                    418:             push(@formelements,('forceedit','forcestudent'));
                    419:         }
                    420:     } else {
                    421:         push(@formelements,('forceedit','forcestudent'));
                    422:     }
                    423:     foreach my $element (@formelements) {
                    424:         if (exists($env{'form.'.$element})) {
1.47      albertel  425:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   426:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    427:             }
                    428:         }
                    429:     }
1.47      albertel  430:     if ($new) {
1.43      raeburn   431:         foreach my $key (keys(%{$new_items})) {
                    432:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    433:         }
                    434:     }
                    435:     $query_string =~ s/^\&amp;/\?/;
                    436:     return $query_string;
                    437: }
                    438: 
                    439: sub display_portfolio_header {
1.55      raeburn   440:     my ($r,$is_course) = @_;
                    441:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   442:     my $query_string = &build_query_string();
                    443:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    444:     my $forcestudent='';
                    445:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55      raeburn   446: 
                    447:     my $output;
                    448:     if ($is_course) {
                    449:         $output = 
                    450:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
                    451:                                             {'function' => $forcestudent,
                    452:                                              'domain'   => $cdom,});
                    453:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
                    454:     } else {
                    455:         $output  =
                    456:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    457:                                             {'function' => $forcestudent,
1.43      raeburn   458:                                              'domain'   => $cdom,});
1.55      raeburn   459:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    460:             &Apache::lonhtmlcommon::add_breadcrumb
                    461:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
                    462:                   text=>"Personal information - $name",
                    463:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
                    464:                   text=>"Viewable files - $name",
                    465:                   title=>"Viewable portfolio files for $name"}
                    466:             );
                    467:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
                    468:         }
                    469:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53      raeburn   470:     }
1.43      raeburn   471:     $r->print($output);
                    472:     return;
                    473: }
                    474: 
                    475: sub display_portfolio_files {
1.55      raeburn   476:     my ($r,$is_course) = @_;
                    477:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.47      albertel  478:     my %lt = ( withoutpass => 'passphrase not required',
                    479: 	       withpass    => 'passphrase protected',
                    480: 	       both        => 'all access types ',);
                    481:     %lt = &Apache::lonlocal::texthash(%lt);
                    482: 
1.43      raeburn   483:     my $portaccess = 'withoutpass';
                    484:     if (exists($env{'form.portaccess'})) {
                    485:         $portaccess = $env{'form.portaccess'};
                    486:     }
1.47      albertel  487: 
1.45      albertel  488:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    489: 	.'" name="displaystatus" method="post">'.
                    490: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   491:     foreach my $type ('withoutpass','withpass','both') {
                    492:         $output .= '<option value="'.$type.'" ';
                    493:         if ($portaccess eq $type) {
                    494:             $output .= 'selected="selected"';
                    495:         }
1.53      raeburn   496:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   497:     }
                    498:     $output .= '</select>'."\n".
                    499:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  500:                &mt('Update display').'" />';
1.43      raeburn   501:     $output .= '</form><br /><br />';
                    502:     $r->print($output);
1.64      raeburn   503:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
                    504:                                       $cdom,$cnum,$name);
1.53      raeburn   505:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    506:         my $query_string = &build_query_string();
                    507:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
1.55      raeburn   508:                   '/aboutme'.$query_string.'">');
                    509:         if ($is_course) {
                    510:             $r->print(&mt('Course Information page'));
                    511:         } else {
                    512:             $r->print(&mt('Information about [_1]',$name));
                    513:         }
                    514:         $r->print('</a>');
1.53      raeburn   515:     }
1.43      raeburn   516:     return;
                    517: }
                    518: 
                    519: sub portfolio_files {
1.64      raeburn   520:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
1.43      raeburn   521:     my $filecounts = {
                    522:                        withpass    => 0,
                    523:                        withoutpass => 0,
                    524:                        both        => 0,
                    525:                      };
                    526:     my $current_permissions =
1.44      albertel  527: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   528:     my %access_controls = 
1.44      albertel  529: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   530:     my $portaccess;
                    531:     if ($mode eq 'showlink') {
                    532:         $portaccess = 'both';
                    533:     } else {
                    534:         $portaccess = 'withoutpass';
                    535:         if (exists($env{'form.portaccess'})) {
                    536:             $portaccess = $env{'form.portaccess'};
                    537:         }
                    538:     }
                    539: 
1.55      raeburn   540:     my $diroutput;
                    541:     if ($is_course) {
                    542:         my %files_by_group;
                    543:         foreach my $filename (sort(keys(%access_controls))) {
                    544:             my ($group,$path) = split('/',$filename,2);
                    545:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
                    546:         }
                    547:         foreach my $group (sort(keys(%files_by_group))) {
                    548:             my %fileshash;
                    549:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
                    550:                                            $is_course,$filecounts,$mode,
                    551:                                            $files_by_group{$group},
                    552:                                            \%fileshash,$group);
                    553:             if ($grpout) {
                    554:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
                    555:             }
                    556:         }
                    557:     } else {
                    558:         my %allfileshash;
                    559:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
                    560:                                       $filecounts,$mode,\%access_controls,
                    561:                                       \%allfileshash);
                    562:     }
                    563:     if ($mode eq 'listfiles') {
                    564:         if ($filecounts->{'both'}) {
                    565:              $r->print($diroutput);
                    566:         } else {
                    567:             my $access_text;
                    568:             if (ref($lt) eq 'HASH') {
                    569:                 $access_text = $lt->{$portaccess};   
                    570:             }
                    571:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
                    572:         }
                    573:     }
                    574:     return $filecounts;
                    575: }
                    576: 
                    577: { 
                    578:     my $count=0;
                    579:     sub portfolio_table_start {
                    580: 	$count=0;
                    581: 	return '<table class="LC_aboutme_port">';
                    582:     }
                    583:     sub portfolio_row_start {
                    584: 	$count++;
                    585: 	my $class = ($count%2)?'LC_odd_row'
                    586: 	                      :'LC_even_row';
                    587: 	return '<tr class="'.$class.'">';
                    588:     }
                    589: }
                    590: 
                    591: sub build_hierarchy {
                    592:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
                    593:         $allfileshash,$group) = @_;
                    594:     foreach my $filename (sort(keys(%{$access_info}))) {
                    595:         my $access_status =
                    596:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
1.43      raeburn   597:         if ($portaccess eq 'both') {
                    598:             if (($access_status ne 'ok') &&
                    599:                 ($access_status !~  /^[^:]+:guest_/)) {
                    600:                 next;
                    601:             }
                    602:         } elsif ($portaccess eq 'withoutpass') {
                    603:             if ($access_status ne 'ok') {
                    604:                 next;
                    605:             }
                    606:         } elsif ($portaccess eq 'withpass') {
                    607:             if ($access_status !~  /^[^:]+:guest_/) {
                    608:                 next;
                    609:             }
                    610:         }
                    611:         if ($mode eq 'listfiles') {
                    612:             $filename =~ s/^\///;
                    613:             my @pathitems = split('/',$filename);
1.55      raeburn   614:             my $lasthash = $allfileshash;
1.43      raeburn   615:             while (@pathitems > 1) {
                    616:                 my $newlevel = shift(@pathitems);
                    617:                 if (!exists($lasthash->{$newlevel})) {
                    618:                     $lasthash->{$newlevel} = {};
                    619:                 }
                    620:                 $lasthash = $lasthash->{$newlevel};
                    621:             }
                    622:             $lasthash->{$pathitems[0]} = $filename;
                    623:         }
                    624:         if ($access_status eq 'ok') {
                    625:             $filecounts->{'withoutpass'} ++;
                    626:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    627:             $filecounts->{'withpass'} ++;
                    628:         }
                    629:     }
                    630:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    631:                               $filecounts->{'withpass'};
1.55      raeburn   632:     my $output;
1.43      raeburn   633:     if ($mode eq 'listfiles') {
1.55      raeburn   634:         if ($filecounts->{'both'} > 0) {
1.45      albertel  635:             $output = &portfolio_table_start();
1.55      raeburn   636:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
                    637:                                         $group);
1.43      raeburn   638:             $output .= '</table>';
                    639:         }
1.45      albertel  640:     }
1.55      raeburn   641:     return $output;
1.45      albertel  642: }
                    643: 
1.43      raeburn   644: sub parse_directory {
1.55      raeburn   645:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
                    646:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45      albertel  647:     $depth++;
                    648:     my $output;
1.49      albertel  649: 
1.55      raeburn   650:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                    651:                                                                 $group);
1.70      raeburn   652:     my $getpropath = 1;
1.49      albertel  653:     my %dirlist = map {
                    654: 	    ((split('&',$_,2))[0],1)
1.70      raeburn   655: 	} &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
1.43      raeburn   656:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  657:         $output .= &portfolio_row_start();
                    658:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   659:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  660:             my $title=&HTML::Entities::encode($item,'<>&"');
                    661:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  662: 	    $output .= '</td><td></td></tr>';
1.49      albertel  663:             $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55      raeburn   664: 					$path.'/'.$item,$is_course,$group);
1.43      raeburn   665:         } else {
1.50      albertel  666: 	    my $file_name; 
                    667: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    668: 		$file_name = $1;
                    669: 	    } else {
                    670: 		$file_name = $currhash->{$item};
                    671: 	    }
                    672: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
1.55      raeburn   673:             my $url;
                    674:             if ($is_course) {
                    675:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
                    676:                        '/portfolio/'.$currhash->{$item};
                    677:             } else { 
                    678: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
                    679: 		       $currhash->{$item};
                    680:             }
1.43      raeburn   681:             my $showname;
1.50      albertel  682: 	    if ($have_meta) {
                    683: 		$showname = &Apache::lonnet::metadata($url,'title');
                    684: 	    }
                    685: 	    if ($showname eq '') {
                    686: 		$showname = $file_name;
                    687: 	    } else {
                    688: 		$showname = $file_name.' ('.$showname.')';
                    689: 	    }
                    690: 
1.45      albertel  691:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  692:             $output .= '<a href="'.$url.'">'.
                    693: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    694: 		'&nbsp;'.$showname.'</a>';
                    695: 	    $output.='</td><td>';
1.50      albertel  696: 	    if ($have_meta) {
1.49      albertel  697: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
1.47      albertel  698: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  699: 		'" class="LC_icon" /></a>';
                    700: 	    }
1.45      albertel  701: 	    $output .= '</td></tr>';
1.43      raeburn   702:         }
                    703:     }
1.45      albertel  704:     return $output;
1.43      raeburn   705: }
1.1       www       706: 
                    707: 1;
                    708: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>