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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.73    ! amueller    4: # $Id: lonaboutme.pm,v 1.72 2008/11/18 10:34:45 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=
1.73    ! amueller  205:                qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'}" style="vertical-align:text-top;float:right;" />};
        !           206: 
1.27      albertel  207: 	   if ($target eq 'tex') {
                    208: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.26      sakharuk  209: 	   }
1.71      amueller  210: 	  # $r->print($image); #Print old Image
1.3       www       211:        }
1.23      sakharuk  212:        if ($allowed) {
1.3       www       213:            $r->print(
1.32      albertel  214: 	 '<form method="post">
1.66      bisitz    215:                <input type="submit" name="delupl" value="'.&mt('Delete Photo').'" />
1.32      albertel  216:           </form>'.
1.3       www       217: 	 '<form method="post" enctype="multipart/form-data">'.
1.18      www       218:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.68      raeburn   219:          '<input type="file" name="uploaddoc" size="50" />'.
                    220:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
1.69      raeburn   221:          '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
1.3       www       222: 	 '</form><form method="post">');
1.32      albertel  223: 
1.2       www       224:        }
1.71      amueller  225: 
                    226: 	
1.57      albertel  227:        foreach my $field (sort(keys(%syllabusfields))) {
                    228:           if (($syllabus{$field}) || ($allowed)) {
                    229:               my $message=$syllabus{$field};
1.38      albertel  230: 	      &Apache::lonfeedback::newline_to_br(\$message);
1.2       www       231:               $message
                    232:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.29      www       233: 	      if ($allowed) {
                    234: 		  $message=&Apache::lonspeller::markeduptext($message);
                    235: 	      }
1.2       www       236: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.22      sakharuk  237: 	      if ($target ne 'tex') {
1.72      amueller  238: 				
                    239: 		Apache::lontemplate::print_template($r,$syllabusfields{$field},$message);
                    240: 				
                    241: 				
                    242: 				
1.22      sakharuk  243: 	      } else {
1.57      albertel  244: 		     $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
1.25      sakharuk  245: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.22      sakharuk  246: 	      }
1.23      sakharuk  247:               if ($allowed) {
1.73    ! amueller  248: 		Apache::lontemplate::print_editbox_template($r,$syllabus{$field},$field);
1.2       www       249: 	      }
                    250: 	  }
                    251:        }
1.71      amueller  252:        if($target ne 'tex')
                    253:        {
                    254: 		
1.72      amueller  255: 		  &print_portfiles_link($r,$is_course);
1.71      amueller  256:  
                    257:       		 $r->print('</div>');
                    258: 			$r->print('<div style="margin:0 0 0 75">');
                    259:         $r->print($image);
                    260: 
                    261: 	$r->print('Kontakt');
                    262: 	$r->print(&Apache::loncommon::messagewrapper(&mt('Send me a message'),$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
                    263: 
                    264: 
                    265:        }
                    266: 
1.23      sakharuk  267:        if ($allowed) {
1.69      raeburn   268:            if ($env{'form.popup'}) {
                    269:                $r->print('<input type="hidden" name="popup" value="'.
                    270:                          $env{'form.popup'}.'" />');
                    271:            }
1.2       www       272: 	   $r->print('</form>');
                    273:        }
1.46      albertel  274:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2       www       275:     } else {
1.17      www       276:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8       www       277:     }
1.43      raeburn   278: 
                    279:     if ($target ne 'tex') {
1.71      amueller  280:         # &print_portfiles_link($r,$is_course); #old Print files
                    281: 
1.43      raeburn   282:     }
                    283: 
1.63      albertel  284:     if ($env{'request.course.id'}
                    285: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    286: 	&& &in_course($cdom,$cnum)) {
                    287: 	if ($target ne 'tex') {
                    288: 	    $r->print('<a name="coursecomment" />');
                    289: 	    $r->print('<hr /><h3>'.
                    290: 		      &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
                    291: 		      &mt('Shared by course faculty and staff').
                    292: 		      &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
                    293: 		      '<br />');
                    294: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    295: 	    $r->print('<hr />');
                    296: 	    if (&Apache::lonnet::allowed('vsa',
                    297: 					 $env{'request.course.id'}) ||
                    298: 		&Apache::lonnet::allowed('vsa',
                    299: 					 $env{'request.course.id'}.'/'.
                    300: 					 $env{'request.course.sec'})) {
                    301: 		$r->print(&Apache::loncommon::track_student_link
                    302: 			  ('View recent activity by this student',
                    303: 			   $cnum,$cdom).('&nbsp;'x2));
1.22      sakharuk  304: 	    }
1.63      albertel  305: 	    $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
                    306: 	} else {
                    307: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
                    308: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    309: 	}
1.1       www       310:     }
1.40      albertel  311:     if ($target ne 'tex') {
1.69      raeburn   312:         if ($env{'form.popup'}) {
                    313:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
                    314:         }
1.71      amueller  315: 	$r->print('<br />'.&mt('Last updated').': '.$lastmod);
                    316: 
1.40      albertel  317: 	$r->print(&Apache::loncommon::end_page());
                    318:     } else {
                    319: 	$r->print('\end{document}');
                    320:     }
1.71      amueller  321: 
                    322:   
                    323: 	
1.1       www       324:     return OK;
1.43      raeburn   325: }
                    326: 
1.63      albertel  327: sub in_course {
                    328:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
                    329:     $type ||= 'any';
                    330:     if (!defined($cdom) || !defined($cnum)) {
                    331: 	my $cid  = $env{'request.course.id'};
                    332: 	$cdom = $env{'course.'.$cid.'.domain'};
                    333: 	$cnum = $env{'course.'.$cid.'.num'};
                    334:     }
                    335:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
                    336:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
                    337:     return 0 if (!@course_roles);
                    338:     return 1 if ($type eq 'any');
                    339:     my $now = time();
                    340:     foreach my $role (@course_roles) {
                    341: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
                    342: 	my $status = 'active';
                    343: 	if ($role_start > 0 && $now < $role_start) {
                    344: 	    $status = 'future';
                    345: 	}
                    346: 	if ($role_end > 0 && $now > $role_end) {
                    347: 	    $status = 'previous';
                    348: 	}
                    349: 	return 1 if ($status eq $type);
                    350:     }
                    351:     return 0;
                    352: }
                    353: 
1.43      raeburn   354: sub aboutme_info {
1.55      raeburn   355:     my ($r,$is_course) = @_;
1.43      raeburn   356:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55      raeburn   357:     my $name;
                    358:     if (!$is_course) {
                    359:         $name = &Apache::loncommon::plainname($cnum,$cdom);
                    360:     }
1.43      raeburn   361:     return ($cdom,$cnum,$name);
                    362: }
                    363: 
                    364: sub print_portfiles_link {
1.55      raeburn   365:     my ($r,$is_course) = @_;
                    366:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.64      raeburn   367:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
                    368:                                       $cdom,$cnum,$name);
1.47      albertel  369:     my $query_string = &build_query_string();
1.43      raeburn   370:     my $output;
1.55      raeburn   371:     my %lt = &Apache::lonlocal::texthash(
                    372:                          vpfi => 'Viewable portfolio files',
                    373:                          vgpf => 'Viewable group portfolio files',
                    374:                          difl => 'Display file listing',
                    375:              );                     
1.43      raeburn   376:     if ($filecounts->{'both'} > 0) {
1.71      amueller  377: 	$output = '<fieldset><legend><b>';
                    378: 	$output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</b></legend><br />';
                    379:         
                    380: 	#$output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
1.47      albertel  381:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55      raeburn   382:                    $query_string.'">'.$lt{'difl'}.
1.43      raeburn   383:                    '</a><br /><br />';
1.53      raeburn   384:         if ($filecounts->{'both'} == 1) {
1.55      raeburn   385:             if ($is_course) {
                    386:                 $output .= &mt('One group portfolio file is available.').'<ul>';
                    387:             } else {
1.56      albertel  388:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55      raeburn   389:             }
1.53      raeburn   390:         } else {
1.55      raeburn   391:             if ($is_course) {
1.56      albertel  392:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55      raeburn   393:             } else {
                    394:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
                    395:             }
1.53      raeburn   396:         }
1.43      raeburn   397:         if ($filecounts->{'withoutpass'}) {
1.54      albertel  398: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43      raeburn   399:         }
                    400:         if ($filecounts->{'withpass'}) {
1.54      albertel  401: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   402:         }
                    403:         $output .= '</ul>';
1.71      amueller  404: 	$output .='</fieldset>';
1.43      raeburn   405:     }
                    406:     $r->print($output);
                    407:     return;
                    408: }
                    409: 
                    410: sub build_query_string {
                    411:     my ($new_items) = @_;
                    412:     my $query_string;
                    413:     my @formelements = ('register'); 
1.47      albertel  414:     my $new = 0;
1.43      raeburn   415:     if (ref($new_items) eq 'HASH') {
1.47      albertel  416:         $new = 1;
1.43      raeburn   417:         if (!defined($new_items->{'forceedit'}) && 
                    418:             !defined($new_items->{'forcestudent'})) {
                    419:             push(@formelements,('forceedit','forcestudent'));
                    420:         }
                    421:     } else {
                    422:         push(@formelements,('forceedit','forcestudent'));
                    423:     }
                    424:     foreach my $element (@formelements) {
                    425:         if (exists($env{'form.'.$element})) {
1.47      albertel  426:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   427:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    428:             }
                    429:         }
                    430:     }
1.47      albertel  431:     if ($new) {
1.43      raeburn   432:         foreach my $key (keys(%{$new_items})) {
                    433:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    434:         }
                    435:     }
                    436:     $query_string =~ s/^\&amp;/\?/;
                    437:     return $query_string;
                    438: }
                    439: 
                    440: sub display_portfolio_header {
1.55      raeburn   441:     my ($r,$is_course) = @_;
                    442:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   443:     my $query_string = &build_query_string();
                    444:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    445:     my $forcestudent='';
                    446:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55      raeburn   447: 
                    448:     my $output;
                    449:     if ($is_course) {
                    450:         $output = 
                    451:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
                    452:                                             {'function' => $forcestudent,
                    453:                                              'domain'   => $cdom,});
                    454:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
                    455:     } else {
                    456:         $output  =
                    457:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    458:                                             {'function' => $forcestudent,
1.43      raeburn   459:                                              'domain'   => $cdom,});
1.55      raeburn   460:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    461:             &Apache::lonhtmlcommon::add_breadcrumb
                    462:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
                    463:                   text=>"Personal information - $name",
                    464:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
                    465:                   text=>"Viewable files - $name",
                    466:                   title=>"Viewable portfolio files for $name"}
                    467:             );
                    468:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
                    469:         }
                    470:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53      raeburn   471:     }
1.43      raeburn   472:     $r->print($output);
                    473:     return;
                    474: }
                    475: 
                    476: sub display_portfolio_files {
1.55      raeburn   477:     my ($r,$is_course) = @_;
                    478:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.47      albertel  479:     my %lt = ( withoutpass => 'passphrase not required',
                    480: 	       withpass    => 'passphrase protected',
                    481: 	       both        => 'all access types ',);
                    482:     %lt = &Apache::lonlocal::texthash(%lt);
                    483: 
1.43      raeburn   484:     my $portaccess = 'withoutpass';
                    485:     if (exists($env{'form.portaccess'})) {
                    486:         $portaccess = $env{'form.portaccess'};
                    487:     }
1.47      albertel  488: 
1.45      albertel  489:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    490: 	.'" name="displaystatus" method="post">'.
                    491: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   492:     foreach my $type ('withoutpass','withpass','both') {
                    493:         $output .= '<option value="'.$type.'" ';
                    494:         if ($portaccess eq $type) {
                    495:             $output .= 'selected="selected"';
                    496:         }
1.53      raeburn   497:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   498:     }
                    499:     $output .= '</select>'."\n".
                    500:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  501:                &mt('Update display').'" />';
1.43      raeburn   502:     $output .= '</form><br /><br />';
                    503:     $r->print($output);
1.64      raeburn   504:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
                    505:                                       $cdom,$cnum,$name);
1.53      raeburn   506:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    507:         my $query_string = &build_query_string();
                    508:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
1.55      raeburn   509:                   '/aboutme'.$query_string.'">');
                    510:         if ($is_course) {
                    511:             $r->print(&mt('Course Information page'));
                    512:         } else {
                    513:             $r->print(&mt('Information about [_1]',$name));
                    514:         }
                    515:         $r->print('</a>');
1.53      raeburn   516:     }
1.43      raeburn   517:     return;
                    518: }
                    519: 
                    520: sub portfolio_files {
1.64      raeburn   521:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
1.43      raeburn   522:     my $filecounts = {
                    523:                        withpass    => 0,
                    524:                        withoutpass => 0,
                    525:                        both        => 0,
                    526:                      };
                    527:     my $current_permissions =
1.44      albertel  528: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   529:     my %access_controls = 
1.44      albertel  530: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   531:     my $portaccess;
                    532:     if ($mode eq 'showlink') {
                    533:         $portaccess = 'both';
                    534:     } else {
                    535:         $portaccess = 'withoutpass';
                    536:         if (exists($env{'form.portaccess'})) {
                    537:             $portaccess = $env{'form.portaccess'};
                    538:         }
                    539:     }
                    540: 
1.55      raeburn   541:     my $diroutput;
                    542:     if ($is_course) {
                    543:         my %files_by_group;
                    544:         foreach my $filename (sort(keys(%access_controls))) {
                    545:             my ($group,$path) = split('/',$filename,2);
                    546:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
                    547:         }
                    548:         foreach my $group (sort(keys(%files_by_group))) {
                    549:             my %fileshash;
                    550:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
                    551:                                            $is_course,$filecounts,$mode,
                    552:                                            $files_by_group{$group},
                    553:                                            \%fileshash,$group);
                    554:             if ($grpout) {
                    555:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
                    556:             }
                    557:         }
                    558:     } else {
                    559:         my %allfileshash;
                    560:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
                    561:                                       $filecounts,$mode,\%access_controls,
                    562:                                       \%allfileshash);
                    563:     }
                    564:     if ($mode eq 'listfiles') {
                    565:         if ($filecounts->{'both'}) {
                    566:              $r->print($diroutput);
                    567:         } else {
                    568:             my $access_text;
                    569:             if (ref($lt) eq 'HASH') {
                    570:                 $access_text = $lt->{$portaccess};   
                    571:             }
                    572:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
                    573:         }
                    574:     }
                    575:     return $filecounts;
                    576: }
                    577: 
                    578: { 
                    579:     my $count=0;
                    580:     sub portfolio_table_start {
                    581: 	$count=0;
                    582: 	return '<table class="LC_aboutme_port">';
                    583:     }
                    584:     sub portfolio_row_start {
                    585: 	$count++;
                    586: 	my $class = ($count%2)?'LC_odd_row'
                    587: 	                      :'LC_even_row';
                    588: 	return '<tr class="'.$class.'">';
                    589:     }
                    590: }
                    591: 
                    592: sub build_hierarchy {
                    593:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
                    594:         $allfileshash,$group) = @_;
                    595:     foreach my $filename (sort(keys(%{$access_info}))) {
                    596:         my $access_status =
                    597:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
1.43      raeburn   598:         if ($portaccess eq 'both') {
                    599:             if (($access_status ne 'ok') &&
                    600:                 ($access_status !~  /^[^:]+:guest_/)) {
                    601:                 next;
                    602:             }
                    603:         } elsif ($portaccess eq 'withoutpass') {
                    604:             if ($access_status ne 'ok') {
                    605:                 next;
                    606:             }
                    607:         } elsif ($portaccess eq 'withpass') {
                    608:             if ($access_status !~  /^[^:]+:guest_/) {
                    609:                 next;
                    610:             }
                    611:         }
                    612:         if ($mode eq 'listfiles') {
                    613:             $filename =~ s/^\///;
                    614:             my @pathitems = split('/',$filename);
1.55      raeburn   615:             my $lasthash = $allfileshash;
1.43      raeburn   616:             while (@pathitems > 1) {
                    617:                 my $newlevel = shift(@pathitems);
                    618:                 if (!exists($lasthash->{$newlevel})) {
                    619:                     $lasthash->{$newlevel} = {};
                    620:                 }
                    621:                 $lasthash = $lasthash->{$newlevel};
                    622:             }
                    623:             $lasthash->{$pathitems[0]} = $filename;
                    624:         }
                    625:         if ($access_status eq 'ok') {
                    626:             $filecounts->{'withoutpass'} ++;
                    627:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    628:             $filecounts->{'withpass'} ++;
                    629:         }
                    630:     }
                    631:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    632:                               $filecounts->{'withpass'};
1.55      raeburn   633:     my $output;
1.43      raeburn   634:     if ($mode eq 'listfiles') {
1.55      raeburn   635:         if ($filecounts->{'both'} > 0) {
1.45      albertel  636:             $output = &portfolio_table_start();
1.55      raeburn   637:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
                    638:                                         $group);
1.43      raeburn   639:             $output .= '</table>';
                    640:         }
1.45      albertel  641:     }
1.55      raeburn   642:     return $output;
1.45      albertel  643: }
                    644: 
1.43      raeburn   645: sub parse_directory {
1.55      raeburn   646:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
                    647:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45      albertel  648:     $depth++;
                    649:     my $output;
1.49      albertel  650: 
1.55      raeburn   651:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                    652:                                                                 $group);
1.70      raeburn   653:     my $getpropath = 1;
1.49      albertel  654:     my %dirlist = map {
                    655: 	    ((split('&',$_,2))[0],1)
1.70      raeburn   656: 	} &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
1.43      raeburn   657:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  658:         $output .= &portfolio_row_start();
                    659:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   660:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  661:             my $title=&HTML::Entities::encode($item,'<>&"');
                    662:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  663: 	    $output .= '</td><td></td></tr>';
1.49      albertel  664:             $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55      raeburn   665: 					$path.'/'.$item,$is_course,$group);
1.43      raeburn   666:         } else {
1.50      albertel  667: 	    my $file_name; 
                    668: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    669: 		$file_name = $1;
                    670: 	    } else {
                    671: 		$file_name = $currhash->{$item};
                    672: 	    }
                    673: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
1.55      raeburn   674:             my $url;
                    675:             if ($is_course) {
                    676:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
                    677:                        '/portfolio/'.$currhash->{$item};
                    678:             } else { 
                    679: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
                    680: 		       $currhash->{$item};
                    681:             }
1.43      raeburn   682:             my $showname;
1.50      albertel  683: 	    if ($have_meta) {
                    684: 		$showname = &Apache::lonnet::metadata($url,'title');
                    685: 	    }
                    686: 	    if ($showname eq '') {
                    687: 		$showname = $file_name;
                    688: 	    } else {
                    689: 		$showname = $file_name.' ('.$showname.')';
                    690: 	    }
                    691: 
1.45      albertel  692:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  693:             $output .= '<a href="'.$url.'">'.
                    694: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    695: 		'&nbsp;'.$showname.'</a>';
                    696: 	    $output.='</td><td>';
1.50      albertel  697: 	    if ($have_meta) {
1.49      albertel  698: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
1.47      albertel  699: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  700: 		'" class="LC_icon" /></a>';
                    701: 	    }
1.45      albertel  702: 	    $output .= '</td></tr>';
1.43      raeburn   703:         }
                    704:     }
1.45      albertel  705:     return $output;
1.43      raeburn   706: }
1.1       www       707: 
                    708: 1;
                    709: __END__

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