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