Annotation of loncom/interface/portfolio.pm, revision 1.196.2.2
1.125 albertel 1: # The LearningOnline Network
2: # portfolio browser
3: #
1.196.2.2! raeburn 4: # $Id: portfolio.pm,v 1.196.2.1 2008/12/12 15:38:53 raeburn Exp $
1.125 albertel 5: #
1.3 banghart 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:
1.1 banghart 29: package Apache::portfolio;
30: use strict;
31: use Apache::Constants qw(:common :http);
1.2 banghart 32: use Apache::loncommon;
1.1 banghart 33: use Apache::lonnet;
1.2 banghart 34: use Apache::lontexconvert;
35: use Apache::lonfeedback;
36: use Apache::lonlocal;
1.82 albertel 37: use Apache::lonnet;
1.99 raeburn 38: use Apache::longroup;
1.132 raeburn 39: use Apache::lonhtmlcommon;
1.113 albertel 40: use HTML::Entities;
1.101 www 41: use LONCAPA;
1.16 banghart 42:
1.137 albertel 43: sub group_args {
44: my $output;
45: if (defined($env{'form.group'})) {
1.138 albertel 46: $output .= '&group='.$env{'form.group'};
1.137 albertel 47: if (defined($env{'form.ref'})) {
48: $output .= '&ref='.$env{'form.ref'};
49: }
50: }
51: return $output;
52: }
53:
54: sub group_form_data {
55: my $output;
56: if (defined($env{'form.group'})) {
1.138 albertel 57: $output = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
1.137 albertel 58: if (exists($env{'form.ref'})) {
59: $output .= '<input type="hidden" name="ref" value="'.
60: $env{'form.ref'}.'" />';
61: }
62: }
1.139 albertel 63: return $output;
1.137 albertel 64: }
65:
1.16 banghart 66: # receives a file name and path stub from username/userfiles/portfolio/
67: # returns an anchor tag consisting encoding filename and currentpath
1.23 albertel 68: sub make_anchor {
1.149 banghart 69: my ($url, $anchor_fields, $inner_text) = @_;
70: if ($$anchor_fields{'continue'} ne 'true') {$$anchor_fields{'continue'} = 'false'};
71: my $anchor = '<a href="'.$url.'?';
72: foreach my $field_name (keys(%$anchor_fields)) {
73: $anchor .= $field_name.'='.$$anchor_fields{$field_name}.'&';
74: }
1.151 banghart 75: $anchor =~ s/&$//;
1.138 albertel 76: $anchor .= &group_args();
1.149 banghart 77: $anchor .= '">'.$inner_text.'</a>';
1.8 albertel 78: return $anchor;
1.6 banghart 79: }
1.138 albertel 80:
1.24 albertel 81: my $dirptr=16384;
1.48 banghart 82: sub display_common {
1.196.2.2! raeburn 83: my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload,$group)=@_;
1.138 albertel 84: my $namespace = &get_namespace();
85: my $port_path = &get_port_path();
1.120 raeburn 86: if ($can_upload) {
1.137 albertel 87: my $groupitem = &group_form_data();
88:
1.120 raeburn 89: my $iconpath= $r->dir_config('lonIconsURL') . "/";
90: my %text=&Apache::lonlocal::texthash(
91: 'upload' => 'Upload',
1.88 albertel 92: 'upload_label' =>
93: 'Upload file to current directory:',
94: 'createdir' => 'Create Subdirectory',
95: 'createdir_label' =>
1.193 raeburn 96: 'Create subdirectory in current directory:',
97: 'parse' => 'If HTML file, upload embedded images/multimedia/css/linked files'
98: );
1.120 raeburn 99: my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
1.168 albertel 100: my $help_fileupload = &Apache::loncommon::help_open_topic('Portfolio AddFiles');
101: my $help_createdir = &Apache::loncommon::help_open_topic('Portfolio CreateDirectory');
1.196.2.2! raeburn 102: my $help_portfolio = &Apache::loncommon::help_open_topic('Portfolio About', &mt('Help on the portfolio'));
! 103: $r->print(&display_usage($group));
1.195 raeburn 104: my $parse_check;
105: if (!&suppress_embed_prompt()) {
106: $parse_check = <<"END";
107: <br />
108: <span class="LC_nobreak">
109: <label>$text{'parse'}
110: <input type="checkbox" name="parserflag" checked="checked" />
111: </label>
112: </span>
113: END
114: }
1.196.2.2! raeburn 115: $r->print(<<"TABLE");
! 116: $help_portfolio
1.114 albertel 117: <table id="LC_portfolio_actions">
118: <tr id="LC_portfolio_upload">
119: <td class="LC_label">
1.113 albertel 120: $text{'upload_label'}
121: </td>
1.120 raeburn 122: <td class="LC_value">
1.113 albertel 123: <form method="post" enctype="multipart/form-data" action="$escuri">
1.120 raeburn 124: $groupitem
1.88 albertel 125: <input name="uploaddoc" type="file" />
126: <input type="hidden" name="currentpath" value="$current_path" />
127: <input type="hidden" name="action" value="$env{"form.action"}" />
128: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
129: <input type="hidden" name="mode" value="$env{"form.mode"}" />
1.195 raeburn 130: <input type="submit" name="storeupl" value="$text{'upload'}" />
131: $help_fileupload
132: $parse_check
1.113 albertel 133: </form>
134: </td>
135: </tr>
1.114 albertel 136: <tr id="LC_portfolio_createdir">
137: <td class="LC_label">
1.113 albertel 138: $text{'createdir_label'}
139: </td>
1.114 albertel 140: <td class="LC_value">
1.113 albertel 141: <form method="post" action="$escuri">
1.196.2.2! raeburn 142: <input name="newdir" type="text" />$groupitem
1.88 albertel 143: <input type="hidden" name="currentpath" value="$current_path" />
144: <input type="hidden" name="action" value="$env{"form.action"}" />
145: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
146: <input type="hidden" name="mode" value="$env{"form.mode"}" />
1.167 rezaferr 147: <input type="submit" name="createdir" value="$text{'createdir'}" />$help_createdir
1.113 albertel 148: </form>
149: </td>
150: </tr>
1.88 albertel 151: </table>
152: TABLE
1.120 raeburn 153: }
1.24 albertel 154: my @tree = split (/\//,$current_path);
1.150 banghart 155: my %anchor_fields = (
1.149 banghart 156: 'selectfile' => $port_path,
157: 'currentpath' => '/',
158: 'mode' => $env{"form.mode"},
159: 'fieldname' => $env{"form.fieldname"},
160: 'continue' => $env{"form.continue"}
161: );
162: $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
1.19 banghart 163: if (@tree > 1){
1.176 albertel 164: my $newCurrentPath = '/';
1.19 banghart 165: for (my $i = 1; $i< @tree; $i++){
166: $newCurrentPath .= $tree[$i].'/';
1.150 banghart 167: my %anchor_fields = (
1.149 banghart 168: 'selectfile' => $tree[$i],
1.176 albertel 169: 'currentpath' => $newCurrentPath,
1.149 banghart 170: 'mode' => $env{"form.mode"},
171: 'fieldname' => $env{"form.fieldname"},
172: 'continue' => $env{"form.continue"}
173: );
174: $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
1.19 banghart 175: }
176: }
1.117 albertel 177: $r->print('</span>');
1.168 albertel 178: $r->print(&Apache::loncommon::help_open_topic('Portfolio ChangeDirectory'));
1.94 raeburn 179: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
1.137 albertel 180: $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.&group_args());
1.94 raeburn 181: $r->print('">'.
182: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
1.22 albertel 183: 'this.form.submit();'));
1.21 banghart 184: $r->print("</form>");
1.48 banghart 185: }
1.137 albertel 186:
1.196.2.2! raeburn 187: sub display_usage {
! 188: my ($group) = @_;
! 189: my $disk_quota = &get_quota($group);
! 190: my $getpropath = 1;
! 191: my $portfolio_root = &get_portfolio_root();
! 192: my ($uname,$udom) = &get_name_dom($group);
! 193: my $current_disk_usage =
! 194: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
! 195: my $usage = $current_disk_usage/1000;
! 196: my $quota = $disk_quota/1000;
! 197: my $percent;
! 198: if ($disk_quota == 0) {
! 199: $percent = 100.0;
! 200: } else {
! 201: $percent = 100*($current_disk_usage/$disk_quota);
! 202: }
! 203: $usage = sprintf("%.2f",$usage);
! 204: $quota = sprintf("%.2f",$quota);
! 205: $percent = sprintf("%.0f",$percent);
! 206: my ($color,$cssclass);
! 207: if ($percent <= 60) {
! 208: $color = '#00A000';
! 209: } elsif ($percent > 60 && $percent < 90) {
! 210: $color = '#FFD300';
! 211: $cssclass = 'class="LC_warning"';
! 212: } elsif( $percent >= 90) {
! 213: $color = '#FF0000';
! 214: $cssclass = 'class="LC_error"';
! 215: }
! 216: my $prog_width = $percent;
! 217: if ($prog_width > 100) {
! 218: $prog_width = 100;
! 219: }
! 220: my $disk_meter = '
! 221: <div align="left" '.$cssclass.'>'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB <span style="font-weight:bold;">('.$percent.'%)</span>',$quota.' MB')."\n".
! 222: ' <div style="display:block; margin-top:5px; margin-bottom:5px; margin-left:0px; margin-right:0px; width:400px; border:1px solid #000000; height:10px;">'."\n".
! 223: ' <div style="display:block; background-color:'.$color.'; width:'.$prog_width.'%; height:10px; color:#000000; margin:0px;"></div>'."\n".
! 224: ' </div>'."\n".
! 225: ' </div><br />';
! 226: return $disk_meter;
! 227: }
! 228:
1.134 banghart 229: sub display_directory_line {
1.156 albertel 230: my ($r,$select_mode, $filename, $mtime, $size, $css_class,
1.137 albertel 231: $line, $access_controls, $curr_access, $now, $version_flag,
1.140 banghart 232: $href_location, $url, $current_path, $access_admin_text, $versions)=@_;
1.156 albertel 233:
234: my $fullpath = &prepend_group($current_path.$filename);
1.137 albertel 235: $r->print('<tr class="'.$css_class.'">');
1.153 banghart 236: $r->print($line); # contains first two cells of table
1.155 banghart 237: my $lock_info;
1.156 albertel 238: if ($version_flag) { # versioned can't be versioned, so TRUE when root file
1.153 banghart 239: $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" /></td>');
1.156 albertel 240: $r->print('<td>'.$version_flag.'</td>');
1.153 banghart 241: } else { # this is a graded or handed back file
1.191 raeburn 242: my ($user,$domain) = &get_name_dom($env{'form.group'});
1.154 banghart 243: my $permissions_hash = &Apache::lonnet::get_portfile_permissions($domain,$user);
1.156 albertel 244: if (defined($$permissions_hash{$fullpath})) {
245: foreach my $array_item (@{$$permissions_hash{$fullpath}}) {
1.155 banghart 246: if (ref($array_item) eq 'ARRAY') {
1.156 albertel 247: if ($$array_item[-1] eq 'handback') {
1.155 banghart 248: $lock_info = 'Handback';
1.156 albertel 249: } elsif ($$array_item[-1] eq 'graded') {
1.155 banghart 250: $lock_info = 'Graded';
1.154 banghart 251: }
1.155 banghart 252: }
1.154 banghart 253: }
254: }
1.156 albertel 255: if ($lock_info) {
256: my %anchor_fields = ('lockinfo' => $fullpath);
1.161 banghart 257: if ($versions) { # hold the folder open
258: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($fullpath);
259: $fname =~ s|^/||;
260: $anchor_fields{'showversions'} = $fname.'.'.$extension;
261: }
1.156 albertel 262: $lock_info = &make_anchor(undef,\%anchor_fields,$lock_info);
263: }
264: $r->print('<td colspan="2">'.$lock_info.'</td>');
1.153 banghart 265: }
266: # $r->print('<td>'.$$version_flag{$filename}.'</td><td>');
267: $r->print('<td>'.&make_anchor($href_location.$filename,undef,$filename).'</td>');
1.137 albertel 268: $r->print('<td>'.$size.'</td>');
269: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
270: if ($select_mode ne 'true') {
1.196.2.1 raeburn 271: $r->print('<td><span class="LC_nobreak">'.
1.137 albertel 272: &mt($curr_access).' ');
1.152 albertel 273: my %anchor_fields = (
1.150 banghart 274: 'access' => $filename,
275: 'currentpath' => $current_path
276: );
277: $r->print(&make_anchor($url, \%anchor_fields, $access_admin_text).'</span></td>');
1.137 albertel 278: }
279: $r->print('</tr>'.$/);
1.134 banghart 280: }
1.137 albertel 281:
1.48 banghart 282: sub display_directory {
1.138 albertel 283: my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
1.137 albertel 284: $can_modify,$can_delete,$can_setacl)=@_;
1.48 banghart 285: my $iconpath= $r->dir_config('lonIconsURL') . "/";
286: my $display_out;
1.77 banghart 287: my $select_mode;
288: my $checked_files;
1.138 albertel 289: my $port_path = &get_port_path();
1.191 raeburn 290: my ($uname,$udom) = &get_name_dom($group);
1.120 raeburn 291: my $access_admin_text = &mt('View Status');
292: if ($can_setacl) {
293: $access_admin_text = &mt('View/Change Status');
294: }
295:
1.102 raeburn 296: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
297: $uname);
298: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
299: $current_permissions,$group);
300: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
301: my $now = time;
1.170 raeburn 302: if ($env{"form.mode"} eq 'selectfile') {
1.77 banghart 303: &select_files($r);
1.94 raeburn 304: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
1.77 banghart 305: $select_mode = 'true';
306: }
1.120 raeburn 307: if ($is_empty && ($current_path ne '/') && $can_delete) {
1.137 albertel 308: $display_out = '<form method="post" action="'.$url.'">'.
309: &group_form_data().
1.30 banghart 310: '<input type="hidden" name="action" value="deletedir" />'.
311: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
312: '<input type="hidden" name="selectfile" value="" />'.
313: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
314: '</form>';
315:
1.48 banghart 316: $r->print($display_out);
1.31 albertel 317: return;
318: }
1.77 banghart 319: if ($select_mode eq 'true') {
1.113 albertel 320: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
1.119 albertel 321: $r->print('<table id="LC_browser">'.
1.146 banghart 322: '<tr><th>Select</th><th> </th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.77 banghart 323: } else {
1.113 albertel 324: $r->print('<form method="post" action="'.$url.'">');
1.168 albertel 325: $r->print(&Apache::loncommon::help_open_topic('Portfolio FileList',
1.187 bisitz 326: &mt('Using the portfolio file list')));
1.119 albertel 327: $r->print('<table id="LC_browser">'.
1.187 bisitz 328: '<tr>'
329: .'<th colspan="2">'.&mt('Actions'). &Apache::loncommon::help_open_topic('Portfolio FileAction').'</th>'
330: .'<th> </th><th> </th>'
331: .'<th>'.&mt('Name').&Apache::loncommon::help_open_topic('Portfolio OpenFile').'</th>'
332: .'<th>'.&mt('Size').'</th>'
333: .'<th>'.&mt('Last Modified').'</th>'
334: .'<th>'.&mt('Current Access Status').&Apache::loncommon::help_open_topic('Portfolio ShareFile').'</th>'
335: .'</tr>');
1.94 raeburn 336: }
1.137 albertel 337: $r->print("\n".&group_form_data()."\n");
338:
1.94 raeburn 339: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
340: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
1.105 banghart 341: my @dir_lines;
342: my %versioned;
1.140 banghart 343: foreach my $dir_line (sort
1.26 albertel 344: {
345: my ($afile)=split('&',$a,2);
346: my ($bfile)=split('&',$b,2);
347: return (lc($afile) cmp lc($bfile));
348: } (@$dir_list)) {
1.140 banghart 349: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
1.77 banghart 350: $filename =~ s/\s+$//;
1.105 banghart 351: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
352: if ($version) {
1.156 albertel 353: my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
354: push(@{ $versioned{$fullpath} },
355: [$filename,$dom,$testdir,$size,$mtime,$obs,]);
1.131 banghart 356: } else {
357: push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
1.105 banghart 358: }
359: }
1.140 banghart 360: foreach my $dir_line (@dir_lines) {
361: my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
1.105 banghart 362: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
1.93 albertel 363: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
1.156 albertel 364: my $version_flag;
1.131 banghart 365: my $show_versions;
1.156 albertel 366: my $fullpath = &prepend_group($current_path.$filename);
1.162 banghart 367: if ($env{'form.showversions'} =~ /$filename/) {
1.131 banghart 368: $show_versions = 'true';
369: }
1.156 albertel 370: if (exists($versioned{$fullpath})) {
1.152 albertel 371: my %anchor_fields = (
1.156 albertel 372: 'selectfile' => $fullpath,
1.150 banghart 373: 'continue' => 'false',
374: 'currentpath' => $current_path,
375: );
1.134 banghart 376: if ($show_versions) {
1.162 banghart 377: # Must preserve other possible showversion files
378: my $version_remainder = $env{'form.showversions'};
379: $version_remainder =~ s/$filename//g;
380: $anchor_fields{'showversions'} = $version_remainder;
1.156 albertel 381: $version_flag = &make_anchor('portfolio',\%anchor_fields,
1.150 banghart 382: '<img class="LC_icon" alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" />');
1.134 banghart 383: } else {
1.162 banghart 384: # allow multiple files to show versioned
385: $anchor_fields{'showversions'} = $env{'form.showversions'}.','.$filename;
1.156 albertel 386: $version_flag = &make_anchor('portfolio',\%anchor_fields,
1.150 banghart 387: '<img class="LC_icon" alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" />');
1.134 banghart 388: }
1.129 banghart 389: } else {
1.156 albertel 390: $version_flag = ' ';
1.129 banghart 391: }
1.23 albertel 392: if ($dirptr&$testdir) {
1.116 albertel 393: my $colspan='colspan="2"';
1.77 banghart 394: if ($select_mode eq 'true'){
1.116 albertel 395: undef($colspan);
1.64 banghart 396: }
1.116 albertel 397: $r->print('<tr class="LC_browser_folder"><td '.$colspan.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_closed.gif" /></td>');
1.188 bisitz 398: $r->print('<td>'.&mt('Go to ...').'</td>');
1.152 albertel 399: my %anchor_fields = (
1.149 banghart 400: 'selectfile' => $filename.'/',
401: 'currentpath' => $current_path.$filename.'/',
402: 'mode' => $env{"form.mode"},
403: 'fieldname' => $env{"form.fieldname"},
404: 'continue' => $env{"form.continue"}
405: );
1.156 albertel 406: $r->print('<td>'.$version_flag.'</td><td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>');
1.47 banghart 407: $r->print('</tr>');
408: } else {
1.116 albertel 409: my $css_class = 'LC_browser_file';
410: my $line;
1.124 albertel 411: if ($select_mode eq 'true') {
1.116 albertel 412: $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
413: if ($$checked_files{$filename} eq 'selected') {
414: $line.=" checked ";
1.77 banghart 415: }
1.116 albertel 416: $line.=' /></td>';
1.77 banghart 417: } else {
1.103 raeburn 418: if (exists $locked_files{$fullpath}) {
1.152 albertel 419: my %anchor_fields = (
1.156 albertel 420: 'lockinfo' => $fullpath
1.150 banghart 421: );
1.188 bisitz 422: $line.='<td colspan="2">'.&make_anchor($url,\%anchor_fields,&mt('Locked')).'</td>';
1.116 albertel 423: $css_class= 'LC_browser_file_locked';
1.77 banghart 424: } else {
1.120 raeburn 425: if (!$can_modify) {
426: $line .= '<td colspan="2">';
427: } else {
428: $line .= '<td>';
429: }
430: if ($can_delete) {
431: $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
432: }
433: if ($can_modify) {
1.146 banghart 434: my $cat='<img class="LC_icon" alt="'.&mt('Catalog Information').
1.120 raeburn 435: '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
1.152 albertel 436: my %anchor_fields = (
1.150 banghart 437: 'rename' => $filename,
438: currentpath => $current_path
439: );
1.188 bisitz 440: $line .= &make_anchor($url,\%anchor_fields,&mt('Rename'));
1.159 banghart 441: $line .= '</td><td>'.&make_anchor($href_edit_location.$filename.'.meta',\%anchor_fields,$cat);
1.150 banghart 442: # '<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
1.120 raeburn 443: }
444: $line .= '</td>';
1.77 banghart 445: }
1.61 banghart 446: }
1.124 albertel 447: my $curr_access;
448: if ($select_mode ne 'true') {
449: my $pub_access = 0;
450: my $guest_access = 0;
451: my $cond_access = 0;
452: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
453: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
454: if (($now > $start) && (!$end || $end > $now)) {
455: if ($scope eq 'public') {
456: $pub_access = 1;
457: } elsif ($scope eq 'guest') {
458: $guest_access = 1;
459: } else {
460: $cond_access = 1;
461: }
462: }
463: }
464: if (!$pub_access && !$guest_access && !$cond_access) {
465: $curr_access = &mt('Private');
466: } else {
467: my @allaccesses;
468: if ($pub_access) {
469: push(@allaccesses,&mt('Public'));
470: }
471: if ($guest_access) {
472: push(@allaccesses,&mt('Passphrase-protected'));
473: }
474: if ($cond_access) {
475: push(@allaccesses,&mt('Conditional'));
476: }
477: $curr_access = join('+ ',@allaccesses);
478: }
479: }
1.156 albertel 480: &display_directory_line($r,$select_mode, $filename, $mtime, $size, $css_class, $line,
481: \%access_controls, $curr_access,$now, $version_flag, $href_location,
1.140 banghart 482: $url, $current_path, $access_admin_text);
1.134 banghart 483: if ($show_versions) {
1.156 albertel 484: foreach my $dir_line (@{ $versioned{$fullpath} }) {
485: my ($v_filename,$dom,$testdir,$size,$mtime,$obs) =
486: @$dir_line;
1.143 banghart 487: $line = '<td colspan="2"> </td>';
1.156 albertel 488: &display_directory_line($r,$select_mode, $v_filename, $mtime, $size,
489: $css_class, $line, \%access_controls, $curr_access, $now,
490: undef, $href_location, $url, $current_path, $access_admin_text, 1);
1.140 banghart 491: }
1.134 banghart 492: }
1.47 banghart 493: }
494: }
495: }
1.77 banghart 496: if ($select_mode eq 'true') {
497: $r->print('</table>
1.127 albertel 498: <input type="hidden" name="continue" value="true" />
499: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
500: <input type="hidden" name="mode" value="selectfile" />
1.60 banghart 501: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
1.48 banghart 502: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
503: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77 banghart 504: </form>');
505: } else {
1.120 raeburn 506: $r->print('</table>');
507: if ($can_delete) {
508: $r->print('
1.196 schafran 509: <input type="submit" name="doit" value="'.&mt('Delete Selected').'" />'.
1.168 albertel 510: &Apache::loncommon::help_open_topic('Portfolio DeleteFile').'
1.77 banghart 511: <input type="hidden" name="action" value="delete" />
512: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.120 raeburn 513: </form>'
514: );
515: }
1.77 banghart 516: }
1.47 banghart 517: }
1.72 banghart 518:
1.24 albertel 519: sub open_form {
1.94 raeburn 520: my ($r,$url)=@_;
1.65 banghart 521: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.102 raeburn 522: $r->print('<form name="portform" method="post" action="'.$url.'">');
1.24 albertel 523: $r->print('<input type="hidden" name="action" value="'.
1.82 albertel 524: $env{'form.action'}.'" />');
1.24 albertel 525: $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65 banghart 526: foreach (@files) {
527: $r->print('<input type="hidden" name="selectfile" value="'.
528: $_.'" />');
529: }
1.24 albertel 530: $r->print('<input type="hidden" name="currentpath" value="'.
1.82 albertel 531: $env{'form.currentpath'}.'" />');
1.24 albertel 532: }
533:
534: sub close_form {
1.137 albertel 535: my ($r,$url,$button_text)=@_;
1.108 raeburn 536: if (!defined($button_text)) {
537: $button_text = {
538: 'continue' => &mt('Continue'),
539: 'cancel' => &mt('Cancel'),
540: };
541: }
1.138 albertel 542: $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
1.137 albertel 543: $r->print(&group_form_data().'</p></form>');
1.112 albertel 544: $r->print('<form action="'.$url.'" method="post">
1.24 albertel 545: <p>
546: <input type="hidden" name="currentpath" value="'.
1.137 albertel 547: $env{'form.currentpath'}.'" />'.
548: &group_form_data());
1.108 raeburn 549: $r->print("\n".' <input type="submit" value="'.$button_text->{'cancel'}.'" />
1.94 raeburn 550: </p></form>');
1.24 albertel 551: }
552:
553: sub display_file {
1.27 albertel 554: my ($path,$filename)=@_;
1.65 banghart 555: my $display_file_text;
1.116 albertel 556: my $file_start='<span class="LC_filename">';
557: my $file_end='</span>';
1.82 albertel 558: if (!defined($path)) { $path=$env{'form.currentpath'}; }
1.65 banghart 559: if (!defined($filename)) {
1.82 albertel 560: $filename=$env{'form.selectfile'};
1.116 albertel 561: $display_file_text = $file_start.$path.$filename.$file_end;
1.65 banghart 562: } elsif (ref($filename) eq "ARRAY") {
1.116 albertel 563: foreach my $file (@$filename) {
564: $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
1.65 banghart 565: }
566: } elsif (ref($filename) eq "SCALAR") {
1.116 albertel 567: $display_file_text = $file_start.$path.$$filename.$file_end;
568: } else {
569: $display_file_text = $file_start.$path.$filename.$file_end;
1.65 banghart 570: }
571: return $display_file_text;
1.24 albertel 572: }
573:
574: sub done {
1.137 albertel 575: my ($message,$url)=@_;
1.76 banghart 576: unless (defined $message) {
577: $message='Done';
578: }
1.153 banghart 579: my %anchor_fields = (
1.161 banghart 580: 'showversions' => $env{'form.showversions'},
1.153 banghart 581: 'currentpath' => $env{'form.currentpath'},
582: 'fieldname' => $env{'form.fieldname'},
583: 'mode' => $env{'form.mode'}
584: );
585: my $result = '<h3>'.&make_anchor($url,\%anchor_fields,&mt($message)).'</h3>';
1.94 raeburn 586: return $result;
1.24 albertel 587: }
588:
589: sub delete {
1.191 raeburn 590: my ($r,$url,$group)=@_;
1.55 banghart 591: my @check;
1.82 albertel 592: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.138 albertel 593: $file_name = &prepend_group($file_name);
1.65 banghart 594: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.191 raeburn 595: my ($uname,$udom) = &get_name_dom($group);
1.94 raeburn 596: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.190 raeburn 597: $r->print(&mt('The file is locked and cannot be deleted.').'<br />');
1.137 albertel 598: $r->print(&done('Back',$url));
1.55 banghart 599: } else {
1.66 banghart 600: if (scalar(@files)) {
1.94 raeburn 601: &open_form($r,$url);
1.188 bisitz 602: $r->print('<p>'.&mt('Delete [_1]?',&display_file(undef,\@files)).'</p>');
1.137 albertel 603: &close_form($r,$url);
1.66 banghart 604: } else {
605: $r->print("No file was checked to delete.<br />");
1.137 albertel 606: $r->print(&done(undef,$url));
1.66 banghart 607: }
1.55 banghart 608: }
1.24 albertel 609: }
610:
611: sub delete_confirmed {
1.164 raeburn 612: my ($r,$url,$group)=@_;
1.65 banghart 613: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
614: my $result;
1.191 raeburn 615: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 616: my $port_path = &get_port_path();
1.164 raeburn 617: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
618: $uname);
1.65 banghart 619: foreach my $delete_file (@files) {
1.94 raeburn 620: $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.82 albertel 621: $env{'form.currentpath'}.
1.65 banghart 622: $delete_file);
623: if ($result ne 'ok') {
1.187 bisitz 624: $r->print('<span class="LC_error">'
625: .&mt('An error occurred ([_1]) while trying to delete [_2].'
626: ,$result,&display_file(undef, $delete_file))
627: .'</span><br /><br />');
1.164 raeburn 628: } else {
629: $r->print(&mt('File: [_1] deleted.',
630: &display_file(undef,$delete_file)));
631: my $file_name = $env{'form.currentpath'}.$delete_file;
632: $file_name = &prepend_group($file_name);
633: my %access_controls =
634: &Apache::lonnet::get_access_controls($current_permissions,
635: $group,$file_name);
636: if (keys(%access_controls) > 0) {
637: my %changes;
1.166 raeburn 638: foreach my $key (keys(%{$access_controls{$file_name}})) {
1.164 raeburn 639: $changes{'delete'}{$key} = 1;
640: }
641: if (keys(%changes) > 0) {
642: my ($outcome,$deloutcome,$new_values,$translation) =
643: &Apache::lonnet::modify_access_controls($file_name,\%changes,
644: $udom,$uname);
645: if ($outcome ne 'ok') {
1.182 albertel 646: $r->print('<br />'.&mt("An error occurred ([_1]) while ".
1.165 albertel 647: "trying to delete access controls for the file.",$outcome).
1.166 raeburn 648: '</span><br /><br />');
1.164 raeburn 649: } else {
650: if ($deloutcome eq 'ok') {
1.166 raeburn 651: $r->print('<br />'.&mt('Access controls also deleted for the file.').'<br /><br />');
1.164 raeburn 652: } else {
1.165 albertel 653: $r->print('<span class="LC_error">'.'<br />'.
1.182 albertel 654: &mt("An error occurred ([_1]) while ".
1.165 albertel 655: "trying to delete access controls for the file.",$deloutcome).
1.166 raeburn 656: '</span><br /><br />');
1.164 raeburn 657: }
658: }
659: }
660: }
1.65 banghart 661: }
1.24 albertel 662: }
1.137 albertel 663: $r->print(&done(undef,$url));
1.24 albertel 664: }
665:
1.30 banghart 666: sub delete_dir {
1.137 albertel 667: my ($r,$url)=@_;
1.94 raeburn 668: &open_form($r,$url);
1.188 bisitz 669: $r->print('<p>'.&mt('Delete [_1]?',&display_file()).'</p>');
1.137 albertel 670: &close_form($r,$url);
1.30 banghart 671: }
672:
673: sub delete_dir_confirmed {
1.191 raeburn 674: my ($r,$url,$group)=@_;
1.82 albertel 675: my $directory_name = $env{'form.currentpath'};
1.81 albertel 676: $directory_name =~ s|/$||; # remove any trailing slash
1.191 raeburn 677: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 678: my $namespace = &get_namespace();
679: my $port_path = &get_port_path();
1.94 raeburn 680: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.30 banghart 681: $directory_name);
1.32 banghart 682:
1.30 banghart 683: if ($result ne 'ok') {
1.188 bisitz 684: $r->print('<span class="LC_error">'
685: .&mt('An error occurred (dir) ([_1]) while trying to delete [_2].'
686: ,$result,$directory_name)
687: .'</span><br />');
1.32 banghart 688: } else {
1.41 banghart 689: # now remove from recent
1.94 raeburn 690: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
1.32 banghart 691: my @dirs = split m!/!, $directory_name;
692: $directory_name='/';
693: for (my $i=1; $i < (@dirs - 1); $i ++){
694: $directory_name .= $dirs[$i].'/';
695: }
1.82 albertel 696: $env{'form.currentpath'} = $directory_name;
1.30 banghart 697: }
1.137 albertel 698: $r->print(&done(undef,$url));
1.30 banghart 699: }
700:
1.24 albertel 701: sub rename {
1.191 raeburn 702: my ($r,$url,$group)=@_;
1.82 albertel 703: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
1.191 raeburn 704: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 705: $file_name = &prepend_group($file_name);
1.94 raeburn 706: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.169 albertel 707: $r->print("The file is locked and cannot be renamed.<br />");
1.137 albertel 708: $r->print(&done(undef,$url));
1.55 banghart 709: } else {
1.94 raeburn 710: &open_form($r,$url);
1.188 bisitz 711: $r->print('<p>'.&mt('Rename [_1] to [_2]?', &display_file()
1.196.2.2! raeburn 712: , '<input name="filenewname" type="text" size="50" />').'</p>');
1.137 albertel 713: &close_form($r,$url);
1.55 banghart 714: }
1.24 albertel 715: }
716:
717: sub rename_confirmed {
1.164 raeburn 718: my ($r,$url,$group)=@_;
1.82 albertel 719: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.191 raeburn 720: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 721: my $port_path = &get_port_path();
1.27 albertel 722: if ($filenewname eq '') {
1.116 albertel 723: $r->print('<span class="LC_error">'.
1.27 albertel 724: &mt("Error: no valid filename was provided to rename to.").
1.116 albertel 725: '</span><br />');
1.137 albertel 726: $r->print(&done(undef,$url));
1.27 albertel 727: return;
728: }
1.164 raeburn 729: my $chg_access;
1.27 albertel 730: my $result=
1.94 raeburn 731: &Apache::lonnet::renameuserfile($uname,$udom,
732: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
733: $port_path.$env{'form.currentpath'}.$filenewname);
1.164 raeburn 734: if ($result eq 'ok') {
735: $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
736: } else {
1.116 albertel 737: $r->print('<span class="LC_error">'.
1.189 raeburn 738: &mt('An error occurred ([_1]) while trying to rename [_2] to [_3].'
1.188 bisitz 739: ,$result,&display_file(),&display_file('',$filenewname))
740: .'</span><br />');
1.164 raeburn 741: return;
1.27 albertel 742: }
1.82 albertel 743: if ($filenewname ne $env{'form.filenewname'}) {
1.116 albertel 744: $r->print(&mt("The new file name was changed from:<br />[_1] to [_2]",
745: '<strong>'.&display_file('',$env{'form.filenewname'}).'</strong>',
746: '<strong>'.&display_file('',$filenewname).'</strong>'));
1.66 banghart 747: }
1.164 raeburn 748: $r->print($chg_access);
1.137 albertel 749: $r->print(&done(undef,$url));
1.27 albertel 750: }
1.102 raeburn 751:
1.164 raeburn 752: sub access_for_renamed {
753: my ($filenewname,$group,$udom,$uname) = @_;
754: my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'};
755: $oldfile = &prepend_group($oldfile);
756: my $newfile = $env{'form.currentpath'}.$filenewname;
757: $newfile = &prepend_group($newfile);
758: my $current_permissions =
1.165 albertel 759: &Apache::lonnet::get_portfile_permissions($udom,$uname);
1.164 raeburn 760: my %access_controls =
1.165 albertel 761: &Apache::lonnet::get_access_controls($current_permissions,
762: $group,$oldfile);
1.164 raeburn 763: my $chg_text;
764: if (keys(%access_controls) > 0) {
765: my %change_old;
766: my %change_new;
1.165 albertel 767: foreach my $key (keys(%{$access_controls{$oldfile}})) {
1.164 raeburn 768: $change_old{'delete'}{$key} = 1;
769: $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key};
770: }
771: my ($outcome,$deloutcome,$new_values,$translation) =
772: &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
1.165 albertel 773: $udom,$uname);
1.164 raeburn 774: if ($outcome ne 'ok') {
1.182 albertel 775: $chg_text ='<br /><br />'.&mt("An error occurred ([_1]) while ".
1.165 albertel 776: "trying to delete access control records for the old name.",$outcome).
1.164 raeburn 777: '</span><br />';
778: } else {
779: if ($deloutcome ne 'ok') {
1.165 albertel 780: $chg_text = '<br /><br /><span class="LC_error"><br />'.
1.182 albertel 781: &mt("An error occurred ([_1]) while ".
1.165 albertel 782: "trying to delete access control records for the old name.",$deloutcome).
783: '</span><br />';
1.164 raeburn 784: }
785: }
786: ($outcome,$deloutcome,$new_values,$translation) =
787: &Apache::lonnet::modify_access_controls($newfile,\%change_new,
788: $udom,$uname);
789: if ($outcome ne 'ok') {
1.165 albertel 790: $chg_text .= '<br /><br />'.
1.182 albertel 791: &mt("An error occurred ([_1]) while ".
1.165 albertel 792: "trying to update access control records for the new name.",$outcome).
1.164 raeburn 793: '</span><br />';
794: }
795: if ($chg_text eq '') {
796: $chg_text = '<br /><br />'.&mt('Access controls updated to reflect the name change.');
797: }
798: }
799: return $chg_text;
800: }
801:
1.104 raeburn 802: sub display_access {
1.170 raeburn 803: my ($r,$url,$group,$can_setacl,$port_path,$action) = @_;
1.191 raeburn 804: my ($uname,$udom) = &get_name_dom($group);
1.104 raeburn 805: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
1.138 albertel 806: $file_name = &prepend_group($file_name);
1.104 raeburn 807: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
808: $uname);
809: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
1.120 raeburn 810: my $aclcount = keys(%access_controls);
1.170 raeburn 811: my ($header,$info);
812: if ($action eq 'chgaccess') {
813: $header = '<h3>'.&mt('Allowing others to retrieve file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>';
814: $info .= &mt('Access to this file by others can be set to be one or more of the following types: public, passphrase-protected or conditional.');
815: $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
816: $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
817: $info .= '</li><li>'.&explain_conditionals();
1.174 raeburn 818: $info .= '</li></ul>'.
1.196.2.1 raeburn 819: &mt('A listing of files viewable without log-in is available at: ')."<a href=\"/adm/$udom/$uname/aboutme/portfolio\">".&Apache::lonnet::absolute_url($ENV{'SERVER_NAME'})."/adm/$udom/$uname/aboutme/portfolio</a>.<br />";
1.170 raeburn 820: if ($group eq '') {
1.174 raeburn 821: $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:");
822: } else {
823: $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
824: }
1.196.2.1 raeburn 825: $info .= "<br /><a href=\"/adm/$udom/$uname/aboutme\">".&Apache::lonnet::absolute_url($ENV{'SERVER_NAME'})."/adm/$udom/$uname/aboutme</a><br />";
1.174 raeburn 826: if ($group ne '') {
827: $info .= &mt("Users with privileges to edit course contents may add a course information page to a course using the 'Course Info' button in DOCS").'<br />';
1.170 raeburn 828: }
829: } else {
830: $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'.
831: &explain_conditionals().'<br />';
1.142 raeburn 832: }
1.120 raeburn 833: if ($can_setacl) {
834: &open_form($r,$url);
835: $r->print($header.$info);
1.187 bisitz 836: $r->print('<br />'.&Apache::loncommon::help_open_topic('Portfolio ShareFile SetAccess', &mt('Help on setting up share access')));
837: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile ChangeSetting', &mt('Help on changing settings')));
838: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile StopAccess', &mt('Help on removing share access')));
1.170 raeburn 839: &access_setting_table($r,$url,$file_name,$access_controls{$file_name},
840: $action);
1.120 raeburn 841: my $button_text = {
1.108 raeburn 842: 'continue' => &mt('Proceed'),
1.188 bisitz 843: 'cancel' => &mt('Return to directory'),
1.108 raeburn 844: };
1.137 albertel 845: &close_form($r,$url,$button_text);
1.120 raeburn 846: } else {
847: $r->print($header);
848: if ($aclcount) {
849: $r->print($info);
850: }
1.137 albertel 851: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
1.120 raeburn 852: }
853: }
854:
1.170 raeburn 855: sub explain_conditionals {
856: return
857: &mt('Conditional files are accessible to logged-in users with accounts in the LON-CAPA network, who satisfy the conditions you set.').'<br />'."\n".
858: &mt('The conditions can include affiliation with a particular course, or a user account in a specific domain.').'<br />'."\n".
859: &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.');
860: }
861:
1.120 raeburn 862: sub view_access_settings {
1.137 albertel 863: my ($r,$url,$access_controls,$aclcount) = @_;
1.120 raeburn 864: my ($showstart,$showend);
865: my %todisplay;
866: foreach my $key (sort(keys(%{$access_controls}))) {
867: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
868: $todisplay{$scope}{$key} = $$access_controls{$key};
869: }
870: if ($aclcount) {
1.188 bisitz 871: $r->print('<h4>'.&mt('Current access controls defined for this file:').'</h4>');
1.120 raeburn 872: $r->print(&Apache::loncommon::start_data_table());
873: $r->print(&Apache::loncommon::start_data_table_header_row());
874: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
875: '</th><th>'.&mt('Additional information').'</th>');
876: $r->print(&Apache::loncommon::end_data_table_header_row());
877: my $count = 1;
878: my $chg = 'none';
879: &build_access_summary($r,$count,$chg,%todisplay);
880: $r->print(&Apache::loncommon::end_data_table());
881: } else {
1.189 raeburn 882: $r->print(&mt('No access control settings currently exist for this file.').'<br />');
1.120 raeburn 883: }
1.153 banghart 884: my %anchor_fields = (
885: 'currentpath' => $env{'form.currentpath'}
886: );
1.188 bisitz 887: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory')));
1.120 raeburn 888: return;
1.104 raeburn 889: }
890:
1.120 raeburn 891: sub build_access_summary {
892: my ($r,$count,$chg,%todisplay) = @_;
893: my ($showstart,$showend);
894: my %scope_desc = (
895: public => 'Public',
896: guest => 'Passphrase-protected',
897: domains => 'Conditional: domain-based',
898: users => 'Conditional: user-based',
899: course => 'Conditional: course-based',
900: );
1.170 raeburn 901: my @allscopes = ('public','guest','domains','users','course');
1.120 raeburn 902: foreach my $scope (@allscopes) {
903: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
904: next;
905: }
906: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
907: if ($count) {
908: $r->print(&Apache::loncommon::start_data_table_row());
909: }
910: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
911: my $content = $todisplay{$scope}{$key};
912: if ($chg eq 'delete') {
913: $showstart = &mt('Deleted');
914: $showend = $showstart;
915: } else {
916: $showstart = localtime($start);
917: if ($end == 0) {
918: $showend = &mt('No end date');
919: } else {
920: $showend = localtime($end);
921: }
922: }
923: $r->print('<td>'.&mt($scope_desc{$scope}));
1.170 raeburn 924: if ($scope eq 'course') {
1.120 raeburn 925: if ($chg ne 'delete') {
926: my $cid = $content->{'domain'}.'_'.$content->{'number'};
927: my %course_description = &Apache::lonnet::coursedescription($cid);
928: $r->print('<br />('.$course_description{'description'}.')');
929: }
930: }
931: $r->print('</td><td>'.&mt('Start: ').$showstart.
932: '<br />'.&mt('End: ').$showend.'</td><td>');
933: if ($chg ne 'delete') {
934: if ($scope eq 'guest') {
935: $r->print(&mt('Passphrase').': '.$content->{'password'});
1.170 raeburn 936: } elsif ($scope eq 'course') {
1.172 raeburn 937: $r->print('<table width="100%"><tr>');
1.120 raeburn 938: $r->print('<th>'.&mt('Roles').'</th><th>'.
939: &mt('Access').'</th><th>'.
940: &mt('Sections').'</th>');
1.170 raeburn 941: $r->print('<th>'.&mt('Groups').'</th>');
1.120 raeburn 942: $r->print('</tr>');
943: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
944: $r->print('<tr>');
945: foreach my $item ('role','access','section','group') {
946: $r->print('<td>');
947: if ($item eq 'role') {
948: my $ucscope = $scope;
949: $ucscope =~ s/^(\w)/uc($1)/e;
950: my $role_output;
951: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
952: if ($role eq 'all') {
953: $role_output .= $role.',';
954: } elsif ($role =~ /^cr/) {
955: $role_output .= (split('/',$role))[3].',';
956: } else {
957: $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
958: }
959: }
960: $role_output =~ s/,$//;
961: $r->print($role_output);
962: } else {
963: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
964: }
1.170 raeburn 965: $r->print('</td>');
1.120 raeburn 966: }
1.170 raeburn 967: $r->print('</tr>');
1.120 raeburn 968: }
1.170 raeburn 969: $r->print('</table>');
1.120 raeburn 970: } elsif ($scope eq 'domains') {
971: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
972: } elsif ($scope eq 'users') {
973: my $curr_user_list = &sort_users($content->{'users'});
974: $r->print(&mt('Users: ').$curr_user_list);
975: } else {
976: $r->print(' ');
977: }
978: } else {
979: $r->print(' ');
980: }
981: $r->print('</td>');
982: $r->print(&Apache::loncommon::end_data_table_row());
983: $count ++;
984: }
985: }
986: }
987:
988:
1.104 raeburn 989: sub update_access {
1.137 albertel 990: my ($r,$url,$group,$port_path) = @_;
1.104 raeburn 991: my $totalprocessed = 0;
992: my %processing;
993: my %title = (
1.108 raeburn 994: 'activate' => 'New control(s) added',
995: 'delete' => 'Existing control(s) deleted',
996: 'update' => 'Existing control(s) modified',
1.104 raeburn 997: );
1.108 raeburn 998: my $changes;
1.104 raeburn 999: foreach my $chg (sort(keys(%title))) {
1000: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
1001: $totalprocessed += @{$processing{$chg}};
1002: foreach my $num (@{$processing{$chg}}) {
1003: my $scope = $env{'form.scope_'.$num};
1004: my ($start,$end) = &get_dates_from_form($num);
1005: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
1006: if ($chg eq 'delete') {
1007: $$changes{$chg}{$newkey} = 1;
1008: } else {
1009: $$changes{$chg}{$newkey} =
1.108 raeburn 1010: &build_access_record($num,$scope,$start,$end,$chg);
1.104 raeburn 1011: }
1012: }
1013: }
1014: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.142 raeburn 1015: $r->print('<h3>'.&mt('Allowing others to retrieve file: [_1]',
1.133 raeburn 1016: $port_path.$file_name).'</h3>'."\n");
1.138 albertel 1017: $file_name = &prepend_group($file_name);
1.191 raeburn 1018: my ($uname,$udom) = &get_name_dom($group);
1.104 raeburn 1019: my ($errors,$outcome,$deloutcome,$new_values,$translation);
1020: if ($totalprocessed) {
1021: ($outcome,$deloutcome,$new_values,$translation) =
1.108 raeburn 1022: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
1023: $uname);
1.104 raeburn 1024: }
1.108 raeburn 1025: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1026: $uname);
1.109 albertel 1027: my %access_controls =
1028: &Apache::lonnet::get_access_controls($current_permissions,
1029: $group,$file_name);
1.104 raeburn 1030: if ($totalprocessed) {
1031: if ($outcome eq 'ok') {
1032: my $updated_controls = $access_controls{$file_name};
1033: my ($showstart,$showend);
1034: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1035: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1036: $r->print('<th>'.&mt('Type of change').'</th><th>'.
1037: &mt('Access control').'</th><th>'.&mt('Dates available').
1038: '</th><th>'.&mt('Additional information').'</th>');
1.110 albertel 1039: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 1040: foreach my $chg (sort(keys(%processing))) {
1041: if (@{$processing{$chg}} > 0) {
1042: if ($chg eq 'delete') {
1043: if (!($deloutcome eq 'ok')) {
1.116 albertel 1044: $errors .='<span class="LC_error">'.
1045: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
1046: '</span>';
1.104 raeburn 1047: next;
1048: }
1049: }
1050: my $numchgs = @{$processing{$chg}};
1051: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1052: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
1053: '.</td>');
1.104 raeburn 1054: my $count = 0;
1.120 raeburn 1055: my %todisplay;
1.104 raeburn 1056: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
1.120 raeburn 1057: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.104 raeburn 1058: my $newkey = $key;
1059: if ($chg eq 'activate') {
1060: $newkey =~ s/^(\d+)/$$translation{$1}/;
1061: }
1.120 raeburn 1062: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
1.104 raeburn 1063: }
1.120 raeburn 1064: &build_access_summary($r,$count,$chg,%todisplay);
1.104 raeburn 1065: }
1066: }
1067: $r->print(&Apache::loncommon::end_data_table());
1068: } else {
1069: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
1.116 albertel 1070: $errors .= '<span class="LC_error">'.
1.179 albertel 1071: &mt('A problem occurred saving access control settings: [_1]',$outcome).
1.116 albertel 1072: '</span>';
1.104 raeburn 1073: }
1074: }
1075: if ($errors) {
1076: $r->print($errors);
1077: }
1078: }
1.108 raeburn 1079: my $allnew = 0;
1080: my $totalnew = 0;
1081: my $status = 'new';
1082: my ($firstitem,$lastitem);
1.170 raeburn 1083: foreach my $newitem ('course','domains','users') {
1.108 raeburn 1084: $allnew += $env{'form.new'.$newitem};
1085: }
1086: if ($allnew > 0) {
1087: my $now = time;
1088: my $then = $now + (60*60*24*180); # six months approx.
1.138 albertel 1089: &open_form($r,$url);
1.170 raeburn 1090: foreach my $newitem ('course','domains','users') {
1.108 raeburn 1091: if ($env{'form.new'.$newitem} > 0) {
1.188 bisitz 1092: $r->print('<br />'.&mt('Add new <b>[_1]-based</b> access control for portfolio file: <b>[_2]</b>',&mt($newitem),$env{'form.currentpath'}.$env{'form.selectfile'}).'<br /><br />');
1.108 raeburn 1093: $firstitem = $totalnew;
1094: $lastitem = $totalnew + $env{'form.new'.$newitem};
1095: $totalnew = $lastitem;
1096: my @numbers;
1097: for (my $i=$firstitem; $i<$lastitem; $i++) {
1098: push (@numbers,$i);
1099: }
1100: &display_access_row($r,$status,$newitem,\@numbers,
1101: $access_controls{$file_name},$now,$then);
1102: }
1103: }
1.137 albertel 1104: &close_form($r,$url);
1.108 raeburn 1105: } else {
1.153 banghart 1106: my %anchor_fields = (
1107: 'currentpath' => $env{'form.currentpath'},
1108: 'access' => $env{'form.selectfile'}
1109: );
1110: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
1111: delete $anchor_fields{'access'};
1.188 bisitz 1112: $r->print(' '.&make_anchor($url,\%anchor_fields,&mt('Return to directory')));
1.108 raeburn 1113: }
1.104 raeburn 1114: return;
1115: }
1116:
1117: sub build_access_record {
1.108 raeburn 1118: my ($num,$scope,$start,$end,$chg) = @_;
1.109 albertel 1119: my $record = {
1120: type => $scope,
1121: time => {
1122: start => $start,
1123: end => $end
1124: },
1125: };
1126:
1127: if ($scope eq 'guest') {
1128: $record->{'password'} = $env{'form.password'};
1.170 raeburn 1129: } elsif ($scope eq 'course') {
1.109 albertel 1130: $record->{'domain'} = $env{'form.crsdom_'.$num};
1131: $record->{'number'} = $env{'form.crsnum_'.$num};
1.108 raeburn 1132: my @role_ids;
1.109 albertel 1133: my @delete_role_ids =
1134: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
1135: my @preserves =
1136: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
1137: if (@delete_role_ids) {
1138: foreach my $id (@preserves) {
1139: if (grep {$_ = $id} (@delete_role_ids)) {
1140: next;
1141: }
1142: push(@role_ids,$id);
1143: }
1144: } else {
1145: push(@role_ids,@preserves);
1146: }
1147:
1148: my $next_id = $env{'form.add_role_'.$num};
1149: if ($next_id) {
1150: push(@role_ids,$next_id);
1151: }
1152:
1.108 raeburn 1153: foreach my $id (@role_ids) {
1154: my (@roles,@accesses,@sections,@groups);
1155: if (($id == $next_id) && ($chg eq 'update')) {
1.109 albertel 1156: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1.108 raeburn 1157: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
1158: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1.109 albertel 1159: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1.108 raeburn 1160: } else {
1161: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
1162: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
1163: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
1164: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
1165: }
1.109 albertel 1166: $record->{'roles'}{$id}{'role'} = \@roles;
1167: $record->{'roles'}{$id}{'access'} = \@accesses;
1168: $record->{'roles'}{$id}{'section'} = \@sections;
1169: $record->{'roles'}{$id}{'group'} = \@groups;
1.108 raeburn 1170: }
1171: } elsif ($scope eq 'domains') {
1172: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1.109 albertel 1173: $record->{'dom'} = \@doms;
1.108 raeburn 1174: } elsif ($scope eq 'users') {
1175: my $userlist = $env{'form.users_'.$num};
1.109 albertel 1176: $userlist =~ s/\s+//sg;
1177: my %userhash = map { ($_,1) } (split(/,/,$userlist));
1178: foreach my $user (keys(%userhash)) {
1.108 raeburn 1179: my ($uname,$udom) = split(/:/,$user);
1.109 albertel 1180: push(@{$record->{'users'}}, {
1181: 'uname' => $uname,
1182: 'udom' => $udom
1183: });
1184: }
1.108 raeburn 1185: }
1.104 raeburn 1186: return $record;
1187: }
1188:
1189: sub get_dates_from_form {
1190: my ($id) = @_;
1191: my $startdate;
1192: my $enddate;
1193: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
1194: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
1195: if ( exists ($env{'form.noend_'.$id}) ) {
1196: $enddate = 0;
1197: }
1198: return ($startdate,$enddate);
1199: }
1200:
1.108 raeburn 1201: sub sort_users {
1.109 albertel 1202: my ($users) = @_;
1203: my @curr_users = map {
1204: $_->{'uname'}.':'.$_->{'udom'}
1205: } (@{$users});
1206: my $curr_user_list = join(",\n",sort(@curr_users));
1.108 raeburn 1207: return $curr_user_list;
1208: }
1209:
1.104 raeburn 1210: sub access_setting_table {
1.170 raeburn 1211: my ($r,$url,$filename,$access_controls,$action) = @_;
1.104 raeburn 1212: my ($public,$publictext);
1.170 raeburn 1213: $publictext ='Off';
1.104 raeburn 1214: my ($guest,$guesttext);
1.170 raeburn 1215: $guesttext = 'Off';
1.104 raeburn 1216: my @courses = ();
1217: my @domains = ();
1218: my @users = ();
1219: my $now = time;
1220: my $then = $now + (60*60*24*180); # six months approx.
1.108 raeburn 1221: my ($num,$scope,$publicnum,$guestnum);
1.170 raeburn 1222: my (%acl_count,%end,%start,%conditionals);
1.104 raeburn 1223: foreach my $key (sort(keys(%{$access_controls}))) {
1.108 raeburn 1224: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1.104 raeburn 1225: if ($scope eq 'public') {
1226: $public = $key;
1.108 raeburn 1227: $publicnum = $num;
1228: $publictext = &acl_status($start{$key},$end{$key},$now);
1229: } elsif ($scope eq 'guest') {
1230: $guest=$key;
1231: $guestnum = $num;
1232: $guesttext = &acl_status($start{$key},$end{$key},$now);
1.170 raeburn 1233: } else {
1234: $conditionals{$scope}{$key} = $$access_controls{$key};
1235: if ($scope eq 'course') {
1236: push(@courses,$key);
1237: } elsif ($scope eq 'domains') {
1238: push(@domains,$key);
1239: } elsif ($scope eq 'users') {
1240: push(@users,$key);
1241: }
1.104 raeburn 1242: }
1.108 raeburn 1243: $acl_count{$scope} ++;
1.104 raeburn 1244: }
1.108 raeburn 1245: $r->print('<table border="0"><tr><td valign="top">');
1.170 raeburn 1246: if ($action eq 'chgaccess') {
1247: &standard_settings($r,$now,$then,$url,$filename,\%acl_count,\%start,
1248: \%end,$public,$publicnum,$publictext,$guest,$guestnum,
1249: $guesttext,$access_controls,%conditionals);
1250: } else {
1251: &condition_setting($r,$access_controls,$now,$then,\%acl_count,
1252: \@domains,\@users,\@courses);
1253: }
1254: $r->print('</td></tr></table>');
1255: }
1256:
1257: sub standard_settings {
1258: my ($r,$now,$then,$url,$filename,$acl_count,$start,$end,$public,$publicnum,
1259: $publictext,$guest,$guestnum,$guesttext,$access_controls,%conditionals)=@_;
1.187 bisitz 1260: $r->print('<h3>'.&mt('Public access: [_1]',&mt($publictext)).'</h3>');
1.104 raeburn 1261: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1262: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1263: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1.110 albertel 1264: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 1265: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1266: if ($public) {
1267: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
1.170 raeburn 1268: &dateboxes($publicnum,$start->{$public},$end->{$public}).'</td>');
1.108 raeburn 1269: } else {
1270: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
1271: &dateboxes('0',$now,$then).'</td>');
1272: }
1273: $r->print(&Apache::loncommon::end_data_table_row());
1274: $r->print(&Apache::loncommon::end_data_table());
1275: $r->print('</td><td width="40"> </td><td valign="top">');
1.187 bisitz 1276: $r->print('<h3>'.&mt('Passphrase-protected access: [_1]',&mt($guesttext)).'</h3>');
1.104 raeburn 1277: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1278: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1279: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1.120 raeburn 1280: '</th><th>'. &mt('Passphrase').'</th>');
1.110 albertel 1281: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1282: $r->print(&Apache::loncommon::start_data_table_row());
1283: my $passwd;
1284: if ($guest) {
1.109 albertel 1285: $passwd = $$access_controls{$guest}{'password'};
1.108 raeburn 1286: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1.170 raeburn 1287: &dateboxes($guestnum,$start->{$guest},$end->{$guest}).'</td>');
1.108 raeburn 1288: } else {
1289: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1290: &dateboxes('1',$now,$then).'</td>');
1.104 raeburn 1291: }
1.108 raeburn 1292: $r->print('<td><input type="text" size="15" name="password" value="'.
1293: $passwd.'" /></td>');
1.104 raeburn 1294: $r->print(&Apache::loncommon::end_data_table_row());
1295: $r->print(&Apache::loncommon::end_data_table());
1.170 raeburn 1296: $r->print('</td></tr><tr><td colspan="3"> </td></tr>'.
1297: '<tr><td colspan="3">');
1298: my $numconditionals = 0;
1299: my $conditionstext;
1300: my %cond_status;
1301: foreach my $scope ('domains','users','course') {
1302: $numconditionals += $acl_count->{$scope};
1303: if ($acl_count->{$scope} > 0) {
1304: if ($conditionstext ne 'Active') {
1305: foreach my $key (keys(%{$conditionals{$scope}})) {
1306: $conditionstext = &acl_status($start->{$key},$end->{$key},$now);
1307: if ($conditionstext eq 'Active') {
1308: last;
1309: }
1310: }
1311: }
1312: }
1313: }
1314: if ($conditionstext eq '') {
1315: $conditionstext = 'Off';
1316: }
1317: my %anchor_fields = (
1318: 'access' => $env{'form.selectfile'},
1319: 'action' => 'chgconditions',
1320: 'currentpath' => $env{'form.currentpath'},
1321: );
1.187 bisitz 1322: $r->print('<h3>'.&mt('Conditional access: [_1]',&mt($conditionstext)).'</h3>');
1.170 raeburn 1323: if ($numconditionals > 0) {
1324: my $count = 1;
1325: my $chg = 'none';
1326: $r->print(&mt('You have previously set [_1] conditional access controls.',$numconditionals).' '.&make_anchor($url,\%anchor_fields,&mt('Change Conditions')).'<br /><br />');
1327: $r->print(&Apache::loncommon::start_data_table());
1328: $r->print(&Apache::loncommon::start_data_table_header_row());
1329: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
1330: '</th><th>'.&mt('Additional information').'</th>');
1331: $r->print(&Apache::loncommon::end_data_table_header_row());
1332: &build_access_summary($r,$count,$chg,%conditionals);
1333: $r->print(&Apache::loncommon::end_data_table());
1334: } else {
1335: $r->print(&make_anchor($url,\%anchor_fields,&mt('Add conditional access')).' '.&mt('based on domain, username, or course affiliation.'));
1336: }
1337: }
1338:
1339: sub condition_setting {
1340: my ($r,$access_controls,$now,$then,$acl_count,$domains,$users,$courses) = @_;
1341: $r->print('<tr><td valign="top">');
1342: &access_element($r,'domains',$acl_count,$domains,$access_controls,$now,$then);
1.158 albertel 1343: $r->print('</td><td> </td><td valign="top">');
1.170 raeburn 1344: &access_element($r,'users',$acl_count,$users,$access_controls,$now,$then);
1.158 albertel 1345: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
1.170 raeburn 1346: if ($acl_count->{course} > 0) {
1.158 albertel 1347: $r->print('<td colspan="3" valign="top">');
1348: } else {
1349: $r->print('<td valign="top">');
1350: }
1.170 raeburn 1351: &access_element($r,'course',$acl_count,$courses,$access_controls,$now,$then);
1.158 albertel 1352: $r->print('</td>');
1.108 raeburn 1353: $r->print('</td></tr></table>');
1354: }
1355:
1356: sub acl_status {
1357: my ($start,$end,$now) = @_;
1358: if ($start > $now) {
1.170 raeburn 1359: return 'Inactive';
1.108 raeburn 1360: }
1361: if ($end && $end<$now) {
1.170 raeburn 1362: return 'Inactive';
1.108 raeburn 1363: }
1.170 raeburn 1364: return 'Active';
1.108 raeburn 1365: }
1366:
1367: sub access_element {
1368: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1369: my $title = $type;
1370: $title =~ s/s$//;
1371: $title =~ s/^(\w)/uc($1)/e;
1.188 bisitz 1372: $r->print('<h3>'.&mt('[_1]-based conditional access: ',&mt($title)));
1.108 raeburn 1373: if ($$acl_count{$type}) {
1374: $r->print($$acl_count{$type}.' ');
1375: if ($$acl_count{$type} > 1) {
1376: $r->print(&mt('conditions'));
1377: } else {
1378: $r->print(&mt('condition'));
1379: }
1380: } else {
1381: $r->print(&mt('Off'));
1382: }
1383: $r->print('</h3>');
1384: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1385: return;
1386: }
1387:
1388: sub display_access_row {
1389: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1390: if (@{$items} > 0) {
1391: my @all_doms;
1392: my $colspan = 3;
1393: my $uctype = $type;
1394: $uctype =~ s/^(\w)/uc($1)/e;
1395: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1396: $r->print(&Apache::loncommon::start_data_table_header_row());
1397: $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
1.108 raeburn 1398: &mt('Dates available').'</th>');
1.172 raeburn 1399: if ($type eq 'course' && $status eq 'old') {
1.108 raeburn 1400: $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
1401: '</th>');
1402: $colspan ++;
1403: } elsif ($type eq 'domains') {
1.178 albertel 1404: @all_doms = sort(&Apache::lonnet::all_domains());
1.108 raeburn 1405: }
1.110 albertel 1406: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1407: foreach my $key (@{$items}) {
1.118 albertel 1408: $r->print(&Apache::loncommon::start_data_table_row());
1.170 raeburn 1409: if ($type eq 'course') {
1.118 albertel 1410: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1.108 raeburn 1411: } elsif ($type eq 'domains') {
1412: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1413: $then);
1414: } elsif ($type eq 'users') {
1415: &users_row($r,$status,$key,$access_controls,$now,$then);
1416: }
1.118 albertel 1417: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1418: }
1419: if ($status eq 'old') {
1.111 albertel 1420: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1421: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1422: '</td>');
1.111 albertel 1423: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1424: }
1425: $r->print(&Apache::loncommon::end_data_table());
1426: } else {
1.188 bisitz 1427: $r->print(&mt('No [_1]-based conditions defined.',&mt($type)).'<br />'
1.187 bisitz 1428: .&additional_item($type));
1.108 raeburn 1429: }
1430: return;
1431: }
1432:
1.110 albertel 1433: sub course_js {
1434: return qq|
1.108 raeburn 1435: <script type="text/javascript">
1.172 raeburn 1436: function setRoleOptions(num,roleid,cdom,cnum,type) {
1437: updateIndexNum = getIndexByValue('update',num);
1438: var addItem = 'add_role_'+num;
1439: var addIndexNum = getIndexByName(addItem);
1440: if (document.portform.elements[addItem].checked) {
1441: document.portform.elements[updateIndexNum].checked = true;
1442: var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1.108 raeburn 1443: var title = 'Roles_Chooser';
1444: var options = 'scrollbars=1,resizable=1,menubar=0';
1445: options += ',width=700,height=600';
1446: rolebrowser = open(url,title,options,'1');
1447: rolebrowser.focus();
1448: } else {
1.172 raeburn 1449: addArray = new Array ('role','access','section','group');
1450: for (var j=0;j<addArray.length;j++) {
1451: var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid);
1452: document.portform.elements[itemIndex].value = '';
1.108 raeburn 1453: }
1454: }
1455: }
1456:
1.172 raeburn 1457: function getIndexByName(item) {
1.108 raeburn 1458: for (var i=0;i<document.portform.elements.length;i++) {
1.172 raeburn 1459: if (document.portform.elements[i].name == item) {
1.108 raeburn 1460: return i;
1461: }
1462: }
1463: return -1;
1464: }
1465:
1.172 raeburn 1466: function getIndexByValue(name,value) {
1.108 raeburn 1467: for (var i=0;i<document.portform.elements.length;i++) {
1468: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1469: return i;
1470: }
1471: }
1472: return -1;
1473: }
1474:
1475: </script>
1.110 albertel 1476: |;
1477: }
1478:
1479: sub course_row {
1.118 albertel 1480: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1.115 raeburn 1481: my $content;
1.110 albertel 1482: my $defdom = $env{'user.domain'};
1483: if ($status eq 'old') {
1.115 raeburn 1484: $content = $$access_controls{$item};
1485: $defdom = $content->{'domain'};
1.110 albertel 1486: }
1487: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1488: .&course_js();
1.120 raeburn 1489: my $uctype = $type;
1490: $uctype =~ s/^(\w)/uc($1)/e;
1.108 raeburn 1491: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1492: $type);
1.110 albertel 1493: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1.108 raeburn 1494: if ($status eq 'old') {
1.115 raeburn 1495: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 1496: my %course_description = &Apache::lonnet::coursedescription($cid);
1.115 raeburn 1497: $r->print('<td><input type="hidden" name="crsdom_'.$num.'" value="'.$content->{'domain'}.'" /><input type="hidden" name="crsnum_'.$num.'" value="'.$content->{'number'}.'" />'.$course_description{'description'}.'</td>');
1.108 raeburn 1498: } elsif ($status eq 'new') {
1.172 raeburn 1499: $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$uctype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
1.108 raeburn 1500: }
1.172 raeburn 1501: $r->print('<td>'.&dateboxes($num,$start,$end));
1502: my $newrole_id = 1;
1.108 raeburn 1503: if ($status eq 'old') {
1.172 raeburn 1504: $r->print('</td><td>');
1.108 raeburn 1505: my $max_id = 0;
1.172 raeburn 1506: if (keys(%{$content->{'roles'}}) > 0) {
1507: $r->print('<table><tr><th>'.&mt('Action').'</th>'.
1508: '<th>'.&mt('Roles').'</th>'.
1509: '<th>'.&mt('Access').'</th>'.
1510: '<th>'.&mt('Sections').'</th>'.
1511: '<th>'.&mt('Groups').'</th></tr>');
1512: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1513: if ($role_id > $max_id) {
1514: $max_id = $role_id;
1515: }
1516: $max_id ++;
1517: my $role_selects = &role_selectors($num,$role_id,$type,$content,'display');
1.196.2.1 raeburn 1518: $r->print('<tr><td><span class="LC_nobreak"><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></span><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
1.172 raeburn 1519: }
1520: $r->print('</table>');
1521: }
1522: $r->print('<br />'.&mt('Add a roles-based condition').
1523: ' <input type="checkbox" name ="add_role_'.
1524: $num.'" onClick="javascript:setRoleOptions('."'$num',
1525: '$max_id','$content->{'domain'}','$content->{'number'}',
1526: '$uctype'".')" value="" />');
1527: $newrole_id = $max_id;
1528: } else {
1529: $r->print('<input type="hidden" name ="add_role_'.$num.'" value="" />');
1.108 raeburn 1530: }
1.172 raeburn 1531: $r->print(&add_course_role($num,$newrole_id));
1532: $r->print('</td>');
1.108 raeburn 1533: return;
1534: }
1535:
1.172 raeburn 1536: sub add_course_role {
1537: my ($num,$max_id) = @_;
1538: my $output;
1539: $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'.
1540: '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'.
1541: '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'.
1542: '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />';
1543: return $output;
1544: }
1545:
1.108 raeburn 1546: sub domains_row {
1547: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1548: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1549: 'domains');
1.112 albertel 1550: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true">'.
1.108 raeburn 1551: ' <option value="">'.&mt('Please select').'</option>';
1552: if ($status eq 'old') {
1.109 albertel 1553: my $content = $$access_controls{$item};
1554: foreach my $dom (@{$all_doms}) {
1555: if ((@{$content->{'dom'}} > 0)
1556: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.108 raeburn 1557: $dom_select .= '<option value="'.$dom.'" selected>'.
1558: $dom.'</option>';
1559: } else {
1560: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1561: }
1562: }
1563: } else {
1564: foreach my $dom (@{$all_doms}) {
1565: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1566: }
1567: }
1.112 albertel 1568: $dom_select .= '</select>';
1.108 raeburn 1569: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1570: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1571: }
1572:
1573: sub users_row {
1574: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1575: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1576: 'users');
1577: my $curr_user_list;
1578: if ($status eq 'old') {
1.109 albertel 1579: my $content = $$access_controls{$item};
1580: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1581: }
1582: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt("Format for users' username:domain information:").'<br /><tt>sparty:msu,illini:uiuc ... etc.</tt><br /><textarea name="users_'.$num.'" cols="30" rows="5">'.$curr_user_list.'</textarea></td><td>'.&dateboxes($num,$start,$end).'</td>');
1583: }
1584:
1585: sub additional_item {
1586: my ($type) = @_;
1.188 bisitz 1587: my $output = &mt('Add new [_1] condition(s)?',&mt($type)).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1.108 raeburn 1588: return $output;
1589: }
1590:
1591: sub actionbox {
1592: my ($status,$num,$scope) = @_;
1.196.2.1 raeburn 1593: my $output = '<span class="LC_nobreak"><label>';
1.108 raeburn 1594: if ($status eq 'new') {
1.170 raeburn 1595: my $checkstate;
1596: if ($scope eq 'domains' || $scope eq 'users' || $scope eq 'course') {
1597: $checkstate = 'checked="checked"';
1598: }
1599: $output .= '<input type="checkbox" name="activate" value="'.$num.'" '.
1600: $checkstate.' />'.
1.108 raeburn 1601: &mt('Activate');
1602: } else {
1603: $output .= '<input type="checkbox" name="delete" value="'.$num.
1.196.2.1 raeburn 1604: '" />'.&mt('Delete').'</label></span><br /><span class="LC_nobreak">'.
1.108 raeburn 1605: '<label><input type="checkbox" name="update" value="'.
1606: $num.'" />'.&mt('Update');
1607: }
1.112 albertel 1608: $output .= '</label></span><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1.108 raeburn 1609: return $output;
1610: }
1611:
1612: sub dateboxes {
1613: my ($num,$start,$end) = @_;
1614: my $noend;
1615: if ($end == 0) {
1616: $noend = 'checked="checked"';
1617: }
1618: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1619: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1620: undef,undef,1);
1621: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1622: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1.196.2.1 raeburn 1623: undef,undef,1). ' <span class="LC_nobreak"><label>'.
1.108 raeburn 1624: '<input type="checkbox" name="noend_'.
1625: $num.'" '.$noend.' />'.&mt('No end date').
1.112 albertel 1626: '</label></span>';
1.108 raeburn 1627:
1628: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1629: return $output;
1630: }
1631:
1632: sub unpack_acc_key {
1633: my ($acc_key) = @_;
1634: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1635: return ($num,$scope,$end,$start);
1636: }
1637:
1638: sub set_identifiers {
1639: my ($status,$item,$now,$then,$scope) = @_;
1640: if ($status eq 'old') {
1641: return(&unpack_acc_key($item));
1642: } else {
1643: return($item,$scope,$then,$now);
1644: }
1645: }
1646:
1647: sub role_selectors {
1.172 raeburn 1648: my ($num,$role_id,$type,$content,$caller) = @_;
1.108 raeburn 1649: my ($output,$cdom,$cnum,$longid);
1650: if ($caller eq 'display') {
1651: $longid = '_'.$num.'_'.$role_id;
1.172 raeburn 1652: $cdom = $$content{'domain'};
1653: $cnum = $$content{'number'};
1.108 raeburn 1654: } elsif ($caller eq 'rolepicker') {
1655: $cdom = $env{'form.cdom'};
1656: $cnum = $env{'form.cnum'};
1657: }
1.120 raeburn 1658: my $uctype = $type;
1659: $uctype =~ s/^(\w)/uc($1)/e;
1.108 raeburn 1660: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1.120 raeburn 1661: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$uctype);
1.108 raeburn 1662: if (!@{$sections}) {
1663: @{$sections} = ('none');
1664: } else {
1665: unshift(@{$sections},('all','none'));
1666: }
1667: if (!@{$groups}) {
1668: @{$groups} = ('none');
1669: } else {
1670: unshift(@{$groups},('all','none'));
1671: }
1672: my @allacesses = sort(keys(%{$accesshash}));
1673: my (%sectionhash,%grouphash);
1674: foreach my $sec (@{$sections}) {
1675: $sectionhash{$sec} = $sec;
1676: }
1677: foreach my $grp (@{$groups}) {
1678: $grouphash{$grp} = $grp;
1679: }
1680: my %lookup = (
1681: 'role' => $rolehash,
1682: 'access' => $accesshash,
1683: 'section' => \%sectionhash,
1684: 'group' => \%grouphash,
1685: );
1686: my @allaccesses = sort(keys(%{$accesshash}));
1687: my %allitems = (
1688: 'role' => $allroles,
1689: 'access' => \@allaccesses,
1690: 'section' => $sections,
1.172 raeburn 1691: 'group' => $groups,
1.108 raeburn 1692: );
1693: foreach my $item ('role','access','section','group') {
1694: $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
1695: foreach my $entry (@{$allitems{$item}}) {
1696: if ($caller eq 'display') {
1697: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1698: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1699: $output .= ' <option value="'.$entry.'" selected>'.
1700: $lookup{$item}{$entry}.'</option>';
1701: next;
1702: }
1703: }
1704: $output .= ' <option value="'.$entry.'">'.
1705: $lookup{$item}{$entry}.'</option>';
1706: }
1707: $output .= '</select>';
1708: }
1709: $output .= '</td>';
1710: return $output;
1711: }
1712:
1713: sub role_options_window {
1714: my ($r) = @_;
1715: my $type = $env{'form.type'};
1.172 raeburn 1716: my $rolenum = $env{'form.setroles'};
1717: my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/);
1718: my $role_elements;
1719: foreach my $item ('role','access','section','group') {
1720: $role_elements .= "'".$item.'_'.$rolenum."',";
1721: }
1722: $role_elements =~ s/,$//;
1723: my $role_selects = &role_selectors($num,$role_id,$type,undef,
1724: 'rolepicker');
1.108 raeburn 1725: $r->print(<<"END_SCRIPT");
1726: <script type="text/javascript">
1727: function setRoles() {
1.172 raeburn 1728: var role_elements = new Array($role_elements);
1729: for (var i=0; i<role_elements.length; i++) {
1.108 raeburn 1730: var copylist = '';
1731: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1732: if (document.rolepicker.elements[i].options[j].selected) {
1733: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1734: }
1735: }
1736: copylist = copylist.substr(0,copylist.length-1);
1.172 raeburn 1737: var openerItem = getIndexByName(role_elements[i]);
1738: opener.document.portform.elements[openerItem].value = copylist;
1.108 raeburn 1739: }
1.172 raeburn 1740: var roleAdder = getIndexByName('add_role_$num');
1741: opener.document.portform.elements[roleAdder].value = '$role_id';
1.108 raeburn 1742: self.close();
1743: }
1.172 raeburn 1744:
1745: function getIndexByName(item) {
1746: for (var i=0;i<opener.document.portform.elements.length;i++) {
1747: if (opener.document.portform.elements[i].name == item) {
1748: return i;
1749: }
1750: }
1751: return -1;
1752: }
1753:
1.108 raeburn 1754: </script>
1755: END_SCRIPT
1756: $r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
1.170 raeburn 1757: $r->print('<form name="rolepicker" action="/adm/portfolio" method="post"><table><tr><th>'.&mt('Roles').'</th><th>'.&mt('[_1] status',$type).'</th><th>'.&mt('Sections').'</th><th>'.&mt('Groups').'</th></tr><tr>'.$role_selects.'</tr></table><br /><input type="button" name="rolepickbutton" value="Save selections" onclick="setRoles()" />');
1.108 raeburn 1758: return;
1.104 raeburn 1759: }
1760:
1.47 banghart 1761: sub select_files {
1.138 albertel 1762: my ($r) = @_;
1.82 albertel 1763: if ($env{'form.continue'} eq 'true') {
1.60 banghart 1764: # here we update the selections for the currentpath
1765: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 1766: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1767: if (scalar(@items)){
1.85 banghart 1768: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 1769: }
1.62 banghart 1770: } else {
1771: #empty the file for a fresh start
1.83 banghart 1772: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 1773: }
1.82 albertel 1774: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 1775: my $java_files = join ",", @files;
1776: if ($java_files) {
1777: $java_files.=',';
1.60 banghart 1778: }
1.63 banghart 1779: my $javascript =(<<ENDSMP);
1.113 albertel 1780: <script type="text/javascript">
1.48 banghart 1781: function finishSelect() {
1.62 banghart 1782: ENDSMP
1.63 banghart 1783: $javascript .= 'fileList = "'.$java_files.'";';
1784: $javascript .= (<<ENDSMP);
1.49 banghart 1785: for (i=0;i<document.forms.checkselect.length;i++) {
1786: if (document.forms.checkselect[i].checked){
1.54 banghart 1787: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 1788: }
1789: }
1.186 albertel 1790: var hwfield = opener.document.getElementsByName('$env{'form.fieldname'}');
1791: hwfield[0].value = fileList;
1.48 banghart 1792: self.close();
1793: }
1794: </script>
1795: ENDSMP
1.63 banghart 1796: $r->print($javascript);
1.185 banghart 1797: $r->print("<h1>".&mt('Select portfolio files')."</h1>".
1798: &mt('Check as many as you wish in response to the problem.')."<br />");
1.88 albertel 1799: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1800: if (@otherfiles) {
1.185 banghart 1801: $r->print("<strong>".&mt('Files selected from other directories:')."</strong><br />");
1.88 albertel 1802: foreach my $file (@otherfiles) {
1803: $r->print($file."<br />");
1804: }
1.60 banghart 1805: }
1.47 banghart 1806: }
1.138 albertel 1807:
1.176 albertel 1808:
1809: sub check_for_upload {
1810: my ($path,$fname,$group,$element) = @_;
1.174 raeburn 1811: my $disk_quota = &get_quota($group);
1.176 albertel 1812: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
1813: my $portfolio_root = &get_portfolio_root();
1814: my $port_path = &get_port_path();
1.191 raeburn 1815: my ($uname,$udom) = &get_name_dom($group);
1.38 banghart 1816: # Fixme --- Move the checking for existing file to LOND error return
1.191 raeburn 1817: my @dir_list=&get_dir_list($portfolio_root,$path,$group);
1.34 banghart 1818: my $found_file = 0;
1.76 banghart 1819: my $locked_file = 0;
1.33 banghart 1820: foreach my $line (@dir_list) {
1.76 banghart 1821: my ($file_name)=split(/\&/,$line,2);
1822: if ($file_name eq $fname){
1.176 albertel 1823: $file_name = $path.$file_name;
1.138 albertel 1824: $file_name = &prepend_group($file_name);
1.33 banghart 1825: $found_file = 1;
1.102 raeburn 1826: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.76 banghart 1827: $locked_file = 1;
1828: }
1.33 banghart 1829: }
1830: }
1.191 raeburn 1831: my $getpropath = 1;
1832: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
1.176 albertel 1833:
1.87 albertel 1834: if (($current_disk_usage + $filesize) > $disk_quota){
1.185 banghart 1835: my $msg = '<span class="LC_error">'.
1836: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
1837: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
1.176 albertel 1838: return ('will_exceed_quota',$msg);
1839: } elsif ($found_file) {
1840: if ($locked_file) {
1.185 banghart 1841: my $msg = '<span class="LC_error">';
1.188 bisitz 1842: $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
1.185 banghart 1843: $msg .= '</span><br />';
1844: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
1.176 albertel 1845: return ('file_locked',$msg);
1846: } else {
1.185 banghart 1847: my $msg = '<span class="LC_error">';
1848: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1849: $msg .= '</span>';
1850: $msg .= '<br />';
1851: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
1.176 albertel 1852: return ('file_exists',$msg);
1853: }
1854: }
1855: }
1856:
1857: sub upload {
1858: my ($r,$url,$group)=@_;
1859: my $fname=&Apache::lonnet::clean_filename($env{'form.uploaddoc.filename'});
1.195 raeburn 1860: my $disk_quota = &get_quota($group);
1861: my $portfolio_root = &get_portfolio_root();
1862: my $port_path = &get_port_path();
1863: my ($uname,$udom) = &get_name_dom($group);
1864: my $getpropath = 1;
1865: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
1866: my ($state,$msg) =
1867: &Apache::loncommon::check_for_upload($env{'form.currentpath'},$fname,
1868: $group,'uploaddoc',$portfolio_root,
1869: $port_path,$disk_quota,
1870: $current_disk_usage,$uname,$udom);
1.176 albertel 1871: if ($state eq 'will_exceed_quota'
1872: || $state eq 'file_locked'
1873: || $state eq 'file_exists' ) {
1874: $r->print($msg.&done('Back',$url));
1875: return;
1876: }
1877:
1878: my (%allfiles,%codebase,$mode);
1879: if ($env{'form.uploaddoc.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
1.193 raeburn 1880: if ($env{'form.parserflag'}) {
1881: $mode = 'parse';
1882: }
1.176 albertel 1883: }
1884: my $result=
1885: &Apache::lonnet::userfileupload('uploaddoc','',
1886: $port_path.$env{'form.currentpath'},
1887: $mode,\%allfiles,\%codebase);
1888: if ($result !~ m|^/uploaded/|) {
1.188 bisitz 1889: $r->print('<span class="LC_error">'.&mt('An error occurred ([_1]) while trying to upload [_2].'
1890: ,$result,&display_file()).'</span><br />');
1.176 albertel 1891: $r->print(&done('Back',$url));
1892: } else {
1893: if (%allfiles) {
1.195 raeburn 1894: if (!&suppress_embed_prompt()) {
1895: my $state = <<STATE;
1.176 albertel 1896: <input type="hidden" name="action" value="upload_embedded" />
1897: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
1898: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
1899: <input type="hidden" name="mode" value="$env{'form.mode'}" />
1900: STATE
1.195 raeburn 1901: $r->print("<h2>".&mt("Reference Warning")."</h2>");
1902: $r->print("<p>".&mt("Completed upload of the file. This file contained references to other files. You must upload the referenced files or else the uploaded file may not work properly.")."</p>");
1903: $r->print("<p>".&mt("Please select the locations from which the referenced files are to be uploaded.")."</p>");
1904: $r->print(&Apache::loncommon::ask_for_embedded_content('/adm/portfolio',$state,\%allfiles,\%codebase,
1.180 albertel 1905: {'error_on_invalid_names' => 1,
1906: 'ignore_remote_references' => 1,}));
1.195 raeburn 1907: $r->print('<p>Or '.&done('Return to directory',$url).'</p>');
1908: }
1.176 albertel 1909: } else {
1910: $r->print(&done(undef,$url));
1911: }
1912: }
1913: }
1914:
1.80 banghart 1915: sub lock_info {
1.137 albertel 1916: my ($r,$url,$group) = @_;
1.191 raeburn 1917: my ($uname,$udom) = &get_name_dom($group);
1.102 raeburn 1918: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1919: $uname);
1.84 banghart 1920: my $file_name = $env{'form.lockinfo'};
1.138 albertel 1921: $file_name = &prepend_group($file_name);
1.102 raeburn 1922: if (defined($file_name) && defined($$current_permissions{$file_name})) {
1923: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1.156 albertel 1924: next if (ref($array_item) ne 'ARRAY');
1925:
1926: my $filetext;
1927: if (defined($group)) {
1928: $filetext = '<strong>'.$env{'form.lockinfo'}.
1929: '</strong> (group: '.$group.')';
1930: } else {
1931: $filetext = '<strong>'.$file_name.'</strong>';
1932: }
1933:
1934: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
1935: '</strong><br />';
1936: if ($$array_item[-1] eq 'graded') {
1937: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1938: $filetext,$title));
1939: } elsif ($$array_item[-1] eq 'handback') {
1940: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
1941: $filetext,$title));
1942: } else {
1943: # submission style lock
1944: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1945: $filetext,$title));
1946: }
1947: my %course_description =
1948: &Apache::lonnet::coursedescription($$array_item[1]);
1949: if ( $course_description{'description'} ne '') {
1.188 bisitz 1950: $r->print(&mt('In the course:').' <strong>'.$course_description{'description'}.'</strong><br />');
1.156 albertel 1951: }
1.102 raeburn 1952: }
1.84 banghart 1953: }
1.185 banghart 1954: $r->print(&done(&mt('Back'),$url));
1.80 banghart 1955: return 'ok';
1956: }
1.138 albertel 1957:
1.25 albertel 1958: sub createdir {
1.191 raeburn 1959: my ($r,$url,$group)=@_;
1.82 albertel 1960: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 1961: if ($newdir eq '') {
1.116 albertel 1962: $r->print('<span class="LC_error">'.
1.37 banghart 1963: &mt("Error: no directory name was provided.").
1.116 albertel 1964: '</span><br />');
1.138 albertel 1965: $r->print(&done(undef,$url));
1.37 banghart 1966: return;
1.94 raeburn 1967: }
1.138 albertel 1968: my $portfolio_root = &get_portfolio_root();
1.191 raeburn 1969: my @dir_list=&get_dir_list($portfolio_root,undef,$group);
1.37 banghart 1970: my $found_file = 0;
1971: foreach my $line (@dir_list) {
1972: my ($filename)=split(/\&/,$line,2);
1973: if ($filename eq $newdir){
1974: $found_file = 1;
1975: }
1976: }
1977: if ($found_file){
1.188 bisitz 1978: $r->print('<span class="LC_error">'
1979: .&mt('Unable to create a directory named [_1].','<strong>'.$newdir.'</strong>')
1980: .' '.&mt('A file or directory by that name already exists.').'</span><br />');
1.37 banghart 1981: } else {
1.191 raeburn 1982: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 1983: my $port_path = &get_port_path();
1.94 raeburn 1984: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
1985: $port_path.$env{'form.currentpath'}.$newdir);
1.37 banghart 1986: if ($result ne 'ok') {
1.188 bisitz 1987: $r->print('<span class="LC_error">'
1988: .&mt('An error occurred ([_1]) while trying to create a new directory [_2].'
1989: ,$result,&display_file())
1990: .'</span><br />');
1.37 banghart 1991: }
1.24 albertel 1992: }
1.82 albertel 1993: if ($newdir ne $env{'form.newdir'}) {
1.188 bisitz 1994: $r->print(&mt('The new directory name was changed from [_1] to [_2].'
1995: ,'<strong>'.$env{'form.newdir'}.'</strong>','<strong>'.$newdir.'</strong>'));
1.67 banghart 1996: }
1.137 albertel 1997: $r->print(&done(undef,$url));
1.94 raeburn 1998: }
1999:
2000: sub get_portfolio_root {
1.163 raeburn 2001: my ($udom,$uname,$group) = @_;
1.160 raeburn 2002: if (!(defined($udom)) || !(defined($uname))) {
1.191 raeburn 2003: ($uname,$udom) = &get_name_dom($group);
1.160 raeburn 2004: }
1.163 raeburn 2005: my $path = '/userfiles/portfolio';
2006: if (!defined($group)) {
2007: if (defined($env{'form.group'})) {
2008: $group = $env{'form.group'};
2009: }
1.94 raeburn 2010: }
1.163 raeburn 2011: if (defined($group)) {
2012: $path = '/userfiles/groups/'.$group.'/portfolio';
2013: }
1.191 raeburn 2014: return $path;
1.94 raeburn 2015: }
2016:
1.126 raeburn 2017: sub get_group_quota {
2018: my ($group) = @_;
2019: my $group_quota;
2020: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2021: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2022: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2023: if (%curr_groups) {
2024: my %group_info = &Apache::longroup::get_group_settings(
2025: $curr_groups{$group});
2026: $group_quota = $group_info{'quota'}; #expressed in Mb
2027: if ($group_quota) {
2028: $group_quota = 1000 * $group_quota; #expressed in k
1.191 raeburn 2029: }
1.126 raeburn 2030: }
2031: return $group_quota;
1.191 raeburn 2032: }
1.126 raeburn 2033:
1.94 raeburn 2034: sub get_dir_list {
1.191 raeburn 2035: my ($portfolio_root,$path,$group) = @_;
1.176 albertel 2036: $path ||= $env{'form.currentpath'};
1.191 raeburn 2037: my ($uname,$udom) = &get_name_dom($group);
2038: my $getpropath = 1;
2039: return &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.94 raeburn 2040: }
2041:
2042: sub get_name_dom {
1.191 raeburn 2043: my ($group) = @_;
1.94 raeburn 2044: my ($uname,$udom);
1.191 raeburn 2045: if (defined($group)) {
1.94 raeburn 2046: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2047: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
2048: } else {
2049: $udom = $env{'user.domain'};
2050: $uname = $env{'user.name'};
2051: }
2052: return ($uname,$udom);
2053: }
2054:
1.102 raeburn 2055: sub prepend_group {
1.138 albertel 2056: my ($filename) = @_;
2057: if (defined($env{'form.group'})) {
2058: $filename = $env{'form.group'}.$filename;
1.102 raeburn 2059: }
2060: return $filename;
2061: }
2062:
1.94 raeburn 2063: sub get_namespace {
2064: my $namespace = 'portfolio';
1.138 albertel 2065: if (defined($env{'form.group'})) {
1.191 raeburn 2066: my ($uname,$udom) = &get_name_dom($env{'form.group'});
1.138 albertel 2067: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
1.94 raeburn 2068: }
2069: return $namespace;
2070: }
2071:
2072: sub get_port_path {
2073: my $port_path;
1.138 albertel 2074: if (defined($env{'form.group'})) {
2075: $port_path = "groups/$env{'form.group'}/portfolio";
1.94 raeburn 2076: } else {
2077: $port_path = 'portfolio';
2078: }
2079: return $port_path;
1.24 albertel 2080: }
2081:
1.120 raeburn 2082: sub missing_priv {
1.138 albertel 2083: my ($r,$url,$priv) = @_;
1.120 raeburn 2084: my $longtext = {
2085: upload => 'upload files',
2086: delete => 'delete files',
2087: rename => 'rename files',
2088: setacl => 'set access controls for files',
2089: };
2090: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
2091: my $rtnlink = '<a href="'.$url;
2092: if ($url =~ /\?/) {
2093: $rtnlink .= '&';
2094: } else {
2095: $rtnlink .= '?';
2096: }
2097: $rtnlink .= 'currentpath='.$escpath;
1.188 bisitz 2098: $r->print('<h3>'.&mt('Action disallowed').'</h3>');
1.120 raeburn 2099: $r->print(&mt('You do not have sufficient privileges to [_1] ',
2100: $longtext->{$priv}));
1.138 albertel 2101: if (defined($env{'form.group'})) {
1.120 raeburn 2102: $r->print(&mt("in the group's file repository."));
1.137 albertel 2103: $rtnlink .= &group_args()
1.120 raeburn 2104: } else {
2105: $r->print(&mt('in this portfolio.'));
2106: }
1.188 bisitz 2107: $rtnlink .= '">'.&mt('Return to directory').'</a>';
1.120 raeburn 2108: $r->print('<br />'.$rtnlink);
2109: $r->print(&Apache::loncommon::end_page());
2110: return;
2111: }
2112:
1.132 raeburn 2113: sub coursegrp_portfolio_header {
1.137 albertel 2114: my ($cdom,$cnum,$grp_desc)=@_;
1.132 raeburn 2115: my $gpterm = &Apache::loncommon::group_term();
2116: my $ucgpterm = $gpterm;
2117: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.137 albertel 2118: if ($env{'form.ref'}) {
1.136 raeburn 2119: &Apache::lonhtmlcommon::add_breadcrumb
2120: ({href=>"/adm/coursegroups",
2121: text=>"Groups",
2122: title=>"Course Groups"});
2123: }
1.132 raeburn 2124: &Apache::lonhtmlcommon::add_breadcrumb
1.138 albertel 2125: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
1.132 raeburn 2126: text=>"$ucgpterm: $grp_desc",
2127: title=>"Go to group's home page"},
1.137 albertel 2128: {href=>"/adm/coursegrp_portfolio?".&group_args(),
1.132 raeburn 2129: text=>"Group Portfolio",
1.136 raeburn 2130: title=>"Display group portfolio"});
1.132 raeburn 2131: my $output = &Apache::lonhtmlcommon::breadcrumbs(
2132: &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
2133: return $output;
2134: }
2135:
1.174 raeburn 2136: sub get_quota {
2137: my ($group) = @_;
2138: my $disk_quota;
2139: if (defined($group)) {
2140: my $grp_quota = &get_group_quota($group); # quota expressed in k
2141: if ($grp_quota ne '') {
2142: $disk_quota = $grp_quota;
2143: } else {
2144: $disk_quota = 0;
2145: }
2146: } else {
2147: $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
2148: $env{'user.domain'}); #expressed in Mb
2149: $disk_quota = 1000 * $disk_quota; # convert from Mb to kb
2150: }
2151: return $disk_quota;
2152: }
2153:
1.195 raeburn 2154: sub suppress_embed_prompt {
2155: my $suppress_prompt = 0;
2156: if (($env{'request.role'} =~ /^st/) && ($env{'request.course.id'} ne '')) {
2157: if ($env{'course.'.$env{'request.course.id'}.'.suppress_embed_prompt'} eq 'yes') {
2158: $suppress_prompt = 1;
2159: }
2160: }
2161: return $suppress_prompt;
2162: }
2163:
2164:
1.24 albertel 2165: sub handler {
2166: # this handles file management
2167: my $r = shift;
1.73 banghart 2168: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.108 raeburn 2169: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
2170: 'fieldname','mode','rename','continue','group','access','setnum',
1.136 raeburn 2171: 'cnum','cdom','type','setroles','showversions','ref']);
1.138 albertel 2172: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
1.94 raeburn 2173: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
2174: $url = $1.$2;
2175: $caller = $2;
2176: }
1.137 albertel 2177: my ($can_modify,$can_delete,$can_upload,$can_setacl);
1.94 raeburn 2178: if ($caller eq 'coursegrp_portfolio') {
2179: # Needs to be in a course
2180: if (! ($env{'request.course.fn'})) {
2181: # Not in a course
2182: $env{'user.error.msg'}=
2183: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
2184: return HTTP_NOT_ACCEPTABLE;
2185: }
2186: my $earlyout = 0;
1.136 raeburn 2187: my $view_permission =
2188: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.137 albertel 2189: $env{'form.group'} =~ s/\W//g;
1.138 albertel 2190: $group = $env{'form.group'};
1.191 raeburn 2191: if ($group ne '') {
2192: ($uname,$udom) = &get_name_dom($group);
1.99 raeburn 2193: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98 albertel 2194: $group);
2195: if (%curr_groups) {
1.132 raeburn 2196: my %grp_content = &Apache::longroup::get_group_settings(
2197: $curr_groups{$group});
2198: $grp_desc = &unescape($grp_content{'description'});
1.94 raeburn 2199: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
2200: $env{'request.course.id'}.'/'.$group))) {
1.138 albertel 2201: $portfolio_root = &get_portfolio_root();
1.94 raeburn 2202: } else {
1.185 banghart 2203: $r->print(&mt('You do not have the privileges required to access the shared files space for this group.'));
1.94 raeburn 2204: $earlyout = 1;
2205: }
2206: } else {
1.185 banghart 2207: $r->print(&mt('Not a valid group for this course'));
1.94 raeburn 2208: $earlyout = 1;
2209: }
1.188 bisitz 2210: $title = &mt('Group files for [_1]', $group);
1.94 raeburn 2211: } else {
1.185 banghart 2212: $r->print(&mt('Invalid group'));
1.94 raeburn 2213: $earlyout = 1;
2214: }
2215: if ($earlyout) { return OK; }
1.126 raeburn 2216: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
1.120 raeburn 2217: $can_modify = 1;
2218: $can_delete = 1;
1.126 raeburn 2219: $can_upload = 1;
2220: $can_setacl = 1;
2221: } else {
2222: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
2223: $can_setacl = 1;
2224: }
2225: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
2226: $can_upload = 1;
2227: }
2228: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
2229: $can_modify = 1;
2230: }
2231: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
2232: $can_delete = 1;
2233: }
1.120 raeburn 2234: }
1.94 raeburn 2235: } else {
2236: ($uname,$udom) = &get_name_dom();
2237: $portfolio_root = &get_portfolio_root();
2238: $title = &mt('Portfolio Manager');
1.120 raeburn 2239: $can_modify = 1;
2240: $can_delete = 1;
2241: $can_upload = 1;
2242: $can_setacl = 1;
1.94 raeburn 2243: }
2244:
1.138 albertel 2245: my $port_path = &get_port_path();
1.24 albertel 2246: &Apache::loncommon::no_cache($r);
2247: &Apache::loncommon::content_type($r,'text/html');
2248: $r->send_http_header;
2249: # Give the LON-CAPA page header
1.82 albertel 2250: if ($env{"form.mode"} eq 'selectfile'){
1.96 albertel 2251: $r->print(&Apache::loncommon::start_page($title,undef,
1.97 albertel 2252: {'only_body' => 1}));
1.108 raeburn 2253: } elsif ($env{'form.action'} eq 'rolepicker') {
2254: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
2255: {'no_nav_bar' => 1, }));
1.74 banghart 2256: } else {
1.97 albertel 2257: $r->print(&Apache::loncommon::start_page($title));
1.74 banghart 2258: }
1.24 albertel 2259: $r->rflush();
1.196.2.2! raeburn 2260: if ($caller ne 'coursegrp_portfolio') {
! 2261: &Apache::lonhtmlcommon::clear_breadcrumbs();
! 2262: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/portfolio",
! 2263: text=>"Portfolio Manager"});
! 2264: if (!&Apache::lonnet::usertools_access($uname,$udom,'portfolio')) {
! 2265: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
! 2266: $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
! 2267: &mt('This is a result of one of the following:').'<ul>'.
! 2268: '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
! 2269: '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
! 2270: '</ul>');
! 2271: $r->print(&Apache::loncommon::end_page());
! 2272: return OK;
! 2273: } else {
! 2274: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Portfolio Manager'));
! 2275: }
1.196.2.1 raeburn 2276: }
1.175 raeburn 2277: my ($blocked,$blocktext) =
2278: &Apache::loncommon::blocking_status('port',$uname,$udom);
2279: if ($blocked) {
2280: $r->print($blocktext);
2281: $r->print(&Apache::loncommon::end_page());
2282: return OK;
2283: }
1.88 albertel 2284: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.185 banghart 2285: $r->print('<span class="LC_error">');
1.188 bisitz 2286: $r->print(&mt('No file was selected to upload.').' ');
2287: $r->print(&mt('To upload a file, click <strong>Browse...</strong> and select a file, then click <strong>Upload</strong>.'));
1.185 banghart 2288: $r->print('</span>');
1.40 banghart 2289: }
1.82 albertel 2290: if ($env{'form.meta'}) {
1.94 raeburn 2291: &open_form($r,$url);
1.185 banghart 2292: $r->print(&mt('Edit the meta data').'<br />');
1.137 albertel 2293: &close_form($r,$url);
1.70 banghart 2294: }
1.82 albertel 2295: if ($env{'form.store'}) {
1.70 banghart 2296: }
2297:
1.82 albertel 2298: if ($env{'form.uploaddoc.filename'}) {
1.120 raeburn 2299: if ($can_upload) {
1.137 albertel 2300: &upload($r,$url,$group);
1.120 raeburn 2301: } else {
1.138 albertel 2302: &missing_priv($r,$url,'upload');
1.120 raeburn 2303: }
1.176 albertel 2304: } elsif ($env{'form.action'} eq 'upload_embedded') {
2305: if ($can_upload) {
1.195 raeburn 2306: my $disk_quota = &get_quota($group);
2307: my $getpropath = 1;
2308: my $current_disk_usage =
2309: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
2310: $r->print(
2311: &Apache::loncommon::upload_embedded('portfolio',$port_path,$uname,$udom,
2312: $group,$portfolio_root,$group,$disk_quota,$current_disk_usage));
2313: $r->print(&done(undef,$url));
1.176 albertel 2314: } else {
2315: &missing_priv($r,$url,'upload');
2316: }
1.82 albertel 2317: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.120 raeburn 2318: if ($can_delete) {
1.164 raeburn 2319: &delete_confirmed($r,$url,$group);
1.120 raeburn 2320: } else {
1.138 albertel 2321: &missing_priv($r,$url,'delete');
1.120 raeburn 2322: }
1.82 albertel 2323: } elsif ($env{'form.action'} eq 'delete') {
1.120 raeburn 2324: if ($can_delete) {
1.191 raeburn 2325: &delete($r,$url,$group);
1.120 raeburn 2326: } else {
1.138 albertel 2327: &missing_priv($r,$url,'delete');
1.120 raeburn 2328: }
1.82 albertel 2329: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.120 raeburn 2330: if ($can_delete) {
1.191 raeburn 2331: &delete_dir_confirmed($r,$url,$group);
1.120 raeburn 2332: } else {
1.138 albertel 2333: &missing_priv($r,$url,'delete');
1.120 raeburn 2334: }
2335: } elsif ($env{'form.action'} eq 'deletedir') {
2336: if ($can_delete) {
1.137 albertel 2337: &delete_dir($r,$url);
1.120 raeburn 2338: } else {
1.138 albertel 2339: &missing_priv($r,$url,'delete');
1.120 raeburn 2340: }
1.82 albertel 2341: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.120 raeburn 2342: if ($can_modify) {
1.164 raeburn 2343: &rename_confirmed($r,$url,$group);
1.120 raeburn 2344: } else {
1.138 albertel 2345: &missing_priv($r,$url,'rename');
1.120 raeburn 2346: }
1.82 albertel 2347: } elsif ($env{'form.rename'}) {
2348: $env{'form.selectfile'} = $env{'form.rename'};
2349: $env{'form.action'} = 'rename';
1.120 raeburn 2350: if ($can_modify) {
1.191 raeburn 2351: &rename($r,$url,$group);
1.120 raeburn 2352: } else {
1.138 albertel 2353: &missing_priv($r,$url,'rename');
1.120 raeburn 2354: }
1.104 raeburn 2355: } elsif ($env{'form.access'}) {
2356: $env{'form.selectfile'} = $env{'form.access'};
1.170 raeburn 2357: if (!defined($env{'form.action'})) {
2358: $env{'form.action'} = 'chgaccess';
2359: }
2360: &display_access($r,$url,$group,$can_setacl,$port_path,$env{'form.action'});
2361: } elsif (($env{'form.action'} eq 'chgaccess') ||
2362: ($env{'form.action'} eq 'chgconditions')) {
1.120 raeburn 2363: if ($can_setacl) {
1.137 albertel 2364: &update_access($r,$url,$group,$port_path);
1.120 raeburn 2365: } else {
1.138 albertel 2366: &missing_priv($r,$url,'setacl');
1.120 raeburn 2367: }
1.108 raeburn 2368: } elsif ($env{'form.action'} eq 'rolepicker') {
1.120 raeburn 2369: if ($can_setacl) {
2370: &role_options_window($r);
2371: } else {
1.138 albertel 2372: &missing_priv($r,$url,'setacl');
1.120 raeburn 2373: }
1.82 albertel 2374: } elsif ($env{'form.createdir'}) {
1.120 raeburn 2375: if ($can_upload) {
1.191 raeburn 2376: &createdir($r,$url,$group);
1.120 raeburn 2377: } else {
1.138 albertel 2378: &missing_priv($r,$url,'upload');
1.120 raeburn 2379: }
1.82 albertel 2380: } elsif ($env{'form.lockinfo'}) {
1.137 albertel 2381: &lock_info($r,$url,$group);
1.24 albertel 2382: } else {
2383: my $current_path='/';
1.82 albertel 2384: if ($env{'form.currentpath'}) {
2385: $current_path = $env{'form.currentpath'};
1.24 albertel 2386: }
1.132 raeburn 2387: if ($caller eq 'coursegrp_portfolio') {
2388: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.137 albertel 2389: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
1.132 raeburn 2390: }
1.192 raeburn 2391: my @dir_list=&get_dir_list($portfolio_root,$current_path,$group);
1.46 albertel 2392: if ($dir_list[0] eq 'no_such_dir'){
2393: # two main reasons for this:
2394: # 1) never been here, so directory structure not created
2395: # 2) back-button navigation after deleting a directory
2396: if ($current_path eq '/'){
1.100 albertel 2397: &Apache::lonnet::mkdiruserfile($uname,$udom,
1.138 albertel 2398: &get_port_path());
1.46 albertel 2399: } else {
2400: # some directory that snuck in get rid of the directory
2401: # from the recent pulldown, just in case
2402: &Apache::lonhtmlcommon::remove_recent('portfolio',
2403: [$current_path]);
2404: $current_path = '/'; # force it back to the root
2405: }
2406: # now grab the directory list again, for the first time
1.192 raeburn 2407: @dir_list=&get_dir_list($portfolio_root,$current_path,$group);
1.43 banghart 2408: }
1.46 albertel 2409: # need to know if directory is empty so it can be removed if desired
2410: my $is_empty=(@dir_list == 2);
1.137 albertel 2411: &display_common($r,$url,$current_path,$is_empty,\@dir_list,
1.196.2.2! raeburn 2412: $can_upload,$group);
1.138 albertel 2413: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
1.137 albertel 2414: $can_upload,$can_modify,$can_delete,$can_setacl);
1.95 albertel 2415: $r->print(&Apache::loncommon::end_page());
1.30 banghart 2416: }
1.90 albertel 2417: return OK;
1.2 banghart 2418: }
1.120 raeburn 2419:
1.1 banghart 2420: 1;
2421: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>