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

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

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