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

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

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