Annotation of loncom/interface/portfolio.pm, revision 1.258
1.125 albertel 1: # The LearningOnline Network
2: # portfolio browser
3: #
1.258 ! raeburn 4: # $Id: portfolio.pm,v 1.257 2016/06/10 22:31:27 raeburn Exp $
1.125 albertel 5: #
1.3 banghart 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
1.1 banghart 29: package Apache::portfolio;
30: use strict;
31: use Apache::Constants qw(:common :http);
1.2 banghart 32: use Apache::loncommon;
1.1 banghart 33: use Apache::lonnet;
1.2 banghart 34: use Apache::lontexconvert;
35: use Apache::lonfeedback;
36: use Apache::lonlocal;
1.82 albertel 37: use Apache::lonnet;
1.99 raeburn 38: use Apache::longroup;
1.132 raeburn 39: use Apache::lonhtmlcommon;
1.113 albertel 40: use HTML::Entities;
1.221 raeburn 41: use LONCAPA qw(:DEFAULT :match);
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.240 bisitz 66: # receives a filename and path stub from username/userfiles/portfolio/
1.16 banghart 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.216 bisitz 91: 'upload' => 'Upload',
92: 'upload_label' => 'Upload file to current directory',
93: 'createdir' => 'Create Subdirectory',
94: 'createdir_label' => 'Create subdirectory in current directory',
95: 'parse' => 'Upload embedded images/multimedia/css/linked files if HTML file',
96: );
1.120 raeburn 97: my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
1.168 albertel 98: my $help_fileupload = &Apache::loncommon::help_open_topic('Portfolio AddFiles');
99: my $help_createdir = &Apache::loncommon::help_open_topic('Portfolio CreateDirectory');
1.206 raeburn 100: my $help_portfolio = &Apache::loncommon::help_open_topic('Portfolio About', &mt('Help on the portfolio'));
1.247 raeburn 101: $r->print(&display_portfolio_usage($group,$help_portfolio));
1.195 raeburn 102: my $parse_check;
103: if (!&suppress_embed_prompt()) {
104: $parse_check = <<"END";
105: <br />
106: <span class="LC_nobreak">
1.216 bisitz 107: <label>
108: <input type="checkbox" name="parserflag" checked="checked" />
109: $lt{'parse'}
1.195 raeburn 110: </label>
111: </span>
112: END
113: }
1.199 bisitz 114:
1.256 musolffc 115: # Find space available before uploading
116: my $free_space = &free_space($group);
117:
1.199 bisitz 118: # Upload File
119: $r->print('<div class="LC_left_float">'
120: .'<form method="post" enctype="multipart/form-data" action="'.$escuri.'">'
121: .'<fieldset>'
122: .'<legend>'.$lt{'upload_label'}.'</legend>'
123: .$groupitem
1.256 musolffc 124: .'<input name="uploaddoc" type="file" class="flUpload" />'
125: .'<input type="hidden" id="free_space" value="'.$free_space.'" />'
1.199 bisitz 126: .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
127: .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
1.235 raeburn 128: .'<input type="hidden" name="symb" value="'.$env{"form.symb"}.'" />'
1.199 bisitz 129: .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
130: .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
131: .'<input type="submit" name="storeupl" value="'.$lt{'upload'}.'" />'
132: .$help_fileupload
133: .$parse_check
134: .'</fieldset>'
135: .'</form>'
136: .'</div>'
137: );
138: # Create Subdirectory
139: $r->print('<div class="LC_left_float">'
140: .'<form method="post" action="'.$escuri.'">'
141: .'<fieldset>'
142: .'<legend>'.$lt{'createdir_label'}.'</legend>'
1.204 raeburn 143: .'<input name="newdir" type="text" />'.$groupitem
1.199 bisitz 144: .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
145: .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
1.235 raeburn 146: .'<input type="hidden" name="symb" value="'.$env{"form.symb"}.'" />'
1.199 bisitz 147: .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
148: .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
149: .'<input type="submit" name="createdir" value="'.$lt{'createdir'}.'" />'
150: .$help_createdir
151: .'</fieldset>'
152: .'</form>'
153: .'</div>'
154: );
155: } # end "if can_upload"
156:
1.24 albertel 157: my @tree = split (/\//,$current_path);
1.150 banghart 158: my %anchor_fields = (
1.149 banghart 159: 'selectfile' => $port_path,
160: 'currentpath' => '/',
161: 'mode' => $env{"form.mode"},
1.235 raeburn 162: 'symb' => $env{"form.symb"},
1.149 banghart 163: 'fieldname' => $env{"form.fieldname"},
164: 'continue' => $env{"form.continue"}
165: );
1.215 bisitz 166: $r->print('<br clear="all" />');
1.149 banghart 167: $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
1.19 banghart 168: if (@tree > 1){
1.176 albertel 169: my $newCurrentPath = '/';
1.19 banghart 170: for (my $i = 1; $i< @tree; $i++){
171: $newCurrentPath .= $tree[$i].'/';
1.150 banghart 172: my %anchor_fields = (
1.149 banghart 173: 'selectfile' => $tree[$i],
1.176 albertel 174: 'currentpath' => $newCurrentPath,
1.149 banghart 175: 'mode' => $env{"form.mode"},
1.235 raeburn 176: 'symb' => $env{"form.symb"},
1.149 banghart 177: 'fieldname' => $env{"form.fieldname"},
178: 'continue' => $env{"form.continue"}
179: );
180: $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
1.19 banghart 181: }
182: }
1.117 albertel 183: $r->print('</span>');
1.168 albertel 184: $r->print(&Apache::loncommon::help_open_topic('Portfolio ChangeDirectory'));
1.94 raeburn 185: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
1.235 raeburn 186: $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.'&symb='.$env{'form.symb'}.&group_args());
1.94 raeburn 187: $r->print('">'.
188: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
1.22 albertel 189: 'this.form.submit();'));
1.21 banghart 190: $r->print("</form>");
1.48 banghart 191: }
1.137 albertel 192:
1.246 raeburn 193: sub display_portfolio_usage {
1.247 raeburn 194: my ($group,$helpitem) = @_;
1.206 raeburn 195: my $disk_quota = &get_quota($group);
196: my $getpropath = 1;
197: my $portfolio_root = &get_portfolio_root();
198: my ($uname,$udom) = &get_name_dom($group);
199: my $current_disk_usage =
200: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
1.246 raeburn 201: return &Apache::loncommon::head_subbox(
1.247 raeburn 202: '<div style="float:right;padding-top:0;margin-top;0">'
203: .$helpitem
204: .'</div>'
205: .'<div>'
1.257 raeburn 206: .&Apache::lonhtmlcommon::display_usage($current_disk_usage,
207: $disk_quota,'portfolio')
1.247 raeburn 208: .'</div>');
1.206 raeburn 209: }
210:
1.134 banghart 211: sub display_directory_line {
1.156 albertel 212: my ($r,$select_mode, $filename, $mtime, $size, $css_class,
1.137 albertel 213: $line, $access_controls, $curr_access, $now, $version_flag,
1.140 banghart 214: $href_location, $url, $current_path, $access_admin_text, $versions)=@_;
1.156 albertel 215:
216: my $fullpath = &prepend_group($current_path.$filename);
1.197 bisitz 217: $r->print(&Apache::loncommon::start_data_table_row());
1.153 banghart 218: $r->print($line); # contains first two cells of table
1.155 banghart 219: my $lock_info;
1.156 albertel 220: if ($version_flag) { # versioned can't be versioned, so TRUE when root file
1.213 droeschl 221: $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" class="LC_fileicon" /></td>');
1.156 albertel 222: $r->print('<td>'.$version_flag.'</td>');
1.153 banghart 223: } else { # this is a graded or handed back file
1.191 raeburn 224: my ($user,$domain) = &get_name_dom($env{'form.group'});
1.154 banghart 225: my $permissions_hash = &Apache::lonnet::get_portfile_permissions($domain,$user);
1.156 albertel 226: if (defined($$permissions_hash{$fullpath})) {
227: foreach my $array_item (@{$$permissions_hash{$fullpath}}) {
1.155 banghart 228: if (ref($array_item) eq 'ARRAY') {
1.156 albertel 229: if ($$array_item[-1] eq 'handback') {
1.155 banghart 230: $lock_info = 'Handback';
1.156 albertel 231: } elsif ($$array_item[-1] eq 'graded') {
1.155 banghart 232: $lock_info = 'Graded';
1.154 banghart 233: }
1.155 banghart 234: }
1.154 banghart 235: }
236: }
1.156 albertel 237: if ($lock_info) {
238: my %anchor_fields = ('lockinfo' => $fullpath);
1.161 banghart 239: if ($versions) { # hold the folder open
1.255 raeburn 240: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($fullpath);
1.161 banghart 241: $fname =~ s|^/||;
242: $anchor_fields{'showversions'} = $fname.'.'.$extension;
243: }
1.156 albertel 244: $lock_info = &make_anchor(undef,\%anchor_fields,$lock_info);
245: }
246: $r->print('<td colspan="2">'.$lock_info.'</td>');
1.153 banghart 247: }
248: # $r->print('<td>'.$$version_flag{$filename}.'</td><td>');
249: $r->print('<td>'.&make_anchor($href_location.$filename,undef,$filename).'</td>');
1.137 albertel 250: $r->print('<td>'.$size.'</td>');
251: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
252: if ($select_mode ne 'true') {
1.197 bisitz 253: $r->print('<td class="'.$css_class.'"> </td>'); # Display status
254: $r->print('<td><span class="LC_nobreak">'
255: .&mt($curr_access).' '
256: );
1.152 albertel 257: my %anchor_fields = (
1.150 banghart 258: 'access' => $filename,
259: 'currentpath' => $current_path
260: );
261: $r->print(&make_anchor($url, \%anchor_fields, $access_admin_text).'</span></td>');
1.197 bisitz 262: } else {
263: $r->print('<td class="'.$css_class.'"> </td>'); # Display status
1.137 albertel 264: }
1.197 bisitz 265: $r->print(&Apache::loncommon::end_data_table_row().$/);
1.134 banghart 266: }
1.137 albertel 267:
1.48 banghart 268: sub display_directory {
1.138 albertel 269: my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
1.137 albertel 270: $can_modify,$can_delete,$can_setacl)=@_;
1.48 banghart 271: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.77 banghart 272: my $select_mode;
273: my $checked_files;
1.138 albertel 274: my $port_path = &get_port_path();
1.191 raeburn 275: my ($uname,$udom) = &get_name_dom($group);
1.120 raeburn 276: my $access_admin_text = &mt('View Status');
277: if ($can_setacl) {
278: $access_admin_text = &mt('View/Change Status');
279: }
280:
1.102 raeburn 281: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
282: $uname);
283: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
284: $current_permissions,$group);
285: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
286: my $now = time;
1.170 raeburn 287: if ($env{"form.mode"} eq 'selectfile') {
1.229 raeburn 288: &select_files($r,$dir_list);
1.223 bisitz 289: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
290: $select_mode = 'true';
1.31 albertel 291: }
1.77 banghart 292: if ($select_mode eq 'true') {
1.113 albertel 293: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
1.197 bisitz 294: $r->print(&Apache::loncommon::start_data_table()
295: .&Apache::loncommon::start_data_table_header_row()
296: .'<th>'.&mt('Select').'</th>'
1.223 bisitz 297: .'<th> </th>'
298: .'<th> </th>'
1.197 bisitz 299: .'<th>'.&mt('Name').'</th>'
300: .'<th>'.&mt('Size').'</th>'
301: .'<th>'.&mt('Last Modified').'</th>'
302: .'<th> </th>'
303: .&Apache::loncommon::end_data_table_header_row()
304: );
1.77 banghart 305: } else {
1.113 albertel 306: $r->print('<form method="post" action="'.$url.'">');
1.223 bisitz 307: $r->print(
308: '<p>'
309: .&Apache::loncommon::help_open_topic(
310: 'Portfolio FileList',
311: &mt('Using the portfolio file list'))
312: .'</p>'
313: );
1.197 bisitz 314: $r->print(&Apache::loncommon::start_data_table()
315: .&Apache::loncommon::start_data_table_header_row()
1.187 bisitz 316: .'<th colspan="2">'.&mt('Actions'). &Apache::loncommon::help_open_topic('Portfolio FileAction').'</th>'
1.223 bisitz 317: .'<th> </th>'
318: .'<th> </th>'
1.187 bisitz 319: .'<th>'.&mt('Name').&Apache::loncommon::help_open_topic('Portfolio OpenFile').'</th>'
320: .'<th>'.&mt('Size').'</th>'
321: .'<th>'.&mt('Last Modified').'</th>'
1.197 bisitz 322: .'<th> </th>'
1.187 bisitz 323: .'<th>'.&mt('Current Access Status').&Apache::loncommon::help_open_topic('Portfolio ShareFile').'</th>'
1.197 bisitz 324: .&Apache::loncommon::end_data_table_header_row());
1.94 raeburn 325: }
1.223 bisitz 326:
327: # Empty directory?
328: if ($is_empty && ($current_path ne '/') && $can_delete) {
329: my $cols = ($select_mode eq 'true') ? 7 : 9;
330: # Empty message
331: $r->print(
332: &Apache::loncommon::start_data_table_row()
333: .'<td colspan="'.$cols.'">'
334: .'<p class="LC_info">'
335: .&mt('This directory is empty.')
336: .'</p>'
337: .'</td>'
338: .&Apache::loncommon::end_data_table_row()
339: .&Apache::loncommon::end_data_table()
340: .'</form>'
341: );
342: # Delete button
343: $r->print(
344: '<form method="post" action="'.$url.'">'.
345: &group_form_data().
346: '<input type="hidden" name="action" value="deletedir" />'.
347: '<p>'.
348: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
349: '</p>'.
350: '<input type="hidden" name="selectfile" value="" />'.
351: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
352: '</form>'
353: );
354: # Directory is empty, so nothing else to display
355: return;
356: }
357:
1.137 albertel 358: $r->print("\n".&group_form_data()."\n");
359:
1.94 raeburn 360: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
361: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
1.105 banghart 362: my @dir_lines;
363: my %versioned;
1.233 raeburn 364: if (ref($dir_list) eq 'ARRAY') {
365: foreach my $dir_line (sort
366: {
367: my ($afile)=split('&',$a,2);
368: my ($bfile)=split('&',$b,2);
369: return (lc($afile) cmp lc($bfile));
370: } (@{$dir_list})) {
371: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
372: $filename =~ s/\s+$//;
1.255 raeburn 373: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($filename);
1.233 raeburn 374: if ($version) {
375: my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
376: push(@{ $versioned{$fullpath} },
377: [$filename,$dom,$testdir,$size,$mtime,$obs,]);
378: } else {
379: push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
380: }
381: }
1.105 banghart 382: }
1.229 raeburn 383: my $zerobyte;
1.140 banghart 384: foreach my $dir_line (@dir_lines) {
385: my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
1.255 raeburn 386: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($filename);
1.93 albertel 387: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
1.156 albertel 388: my $version_flag;
1.131 banghart 389: my $show_versions;
1.156 albertel 390: my $fullpath = &prepend_group($current_path.$filename);
1.162 banghart 391: if ($env{'form.showversions'} =~ /$filename/) {
1.131 banghart 392: $show_versions = 'true';
393: }
1.156 albertel 394: if (exists($versioned{$fullpath})) {
1.152 albertel 395: my %anchor_fields = (
1.156 albertel 396: 'selectfile' => $fullpath,
1.150 banghart 397: 'continue' => 'false',
398: 'currentpath' => $current_path,
399: );
1.134 banghart 400: if ($show_versions) {
1.162 banghart 401: # Must preserve other possible showversion files
402: my $version_remainder = $env{'form.showversions'};
403: $version_remainder =~ s/$filename//g;
404: $anchor_fields{'showversions'} = $version_remainder;
1.156 albertel 405: $version_flag = &make_anchor('portfolio',\%anchor_fields,
1.150 banghart 406: '<img class="LC_icon" alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" />');
1.134 banghart 407: } else {
1.162 banghart 408: # allow multiple files to show versioned
409: $anchor_fields{'showversions'} = $env{'form.showversions'}.','.$filename;
1.156 albertel 410: $version_flag = &make_anchor('portfolio',\%anchor_fields,
1.150 banghart 411: '<img class="LC_icon" alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" />');
1.134 banghart 412: }
1.129 banghart 413: } else {
1.156 albertel 414: $version_flag = ' ';
1.129 banghart 415: }
1.23 albertel 416: if ($dirptr&$testdir) {
1.197 bisitz 417: my $colspan_folder='';
418: my $colspan_fill='';
1.77 banghart 419: if ($select_mode eq 'true'){
1.197 bisitz 420: $colspan_fill=' colspan="3"';
421: } else {
422: $colspan_folder=' colspan="2"';
423: $colspan_fill=' colspan="4"';
1.64 banghart 424: }
1.197 bisitz 425: $r->print('<tr class="LC_browser_folder">');
1.213 droeschl 426: $r->print('<td'.$colspan_folder.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'navmap.folder.closed.gif" class="LC_fileicon" /></td>'
1.197 bisitz 427: .'<td>'.&mt('Go to ...').'</td>');
1.152 albertel 428: my %anchor_fields = (
1.149 banghart 429: 'selectfile' => $filename.'/',
430: 'currentpath' => $current_path.$filename.'/',
431: 'mode' => $env{"form.mode"},
1.235 raeburn 432: 'symb' => $env{"form.symb"},
1.149 banghart 433: 'fieldname' => $env{"form.fieldname"},
434: 'continue' => $env{"form.continue"}
435: );
1.197 bisitz 436: $r->print('<td>'.$version_flag.'</td>'
437: .'<td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>');
438: $r->print('<td'.$colspan_fill.'> </td>');
1.47 banghart 439: $r->print('</tr>');
440: } else {
1.116 albertel 441: my $css_class = 'LC_browser_file';
442: my $line;
1.124 albertel 443: if ($select_mode eq 'true') {
1.229 raeburn 444: if ($size > 0) {
445: $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
446: if ($$checked_files{$filename} eq 'selected') {
447: $line.=' checked="checked" ';
448: }
449: $line.=' /></td>';
450: } else {
451: $line = '<td> </td>';
452: $zerobyte ++;
1.77 banghart 453: }
454: } else {
1.103 raeburn 455: if (exists $locked_files{$fullpath}) {
1.152 albertel 456: my %anchor_fields = (
1.156 albertel 457: 'lockinfo' => $fullpath
1.150 banghart 458: );
1.188 bisitz 459: $line.='<td colspan="2">'.&make_anchor($url,\%anchor_fields,&mt('Locked')).'</td>';
1.116 albertel 460: $css_class= 'LC_browser_file_locked';
1.77 banghart 461: } else {
1.120 raeburn 462: if (!$can_modify) {
463: $line .= '<td colspan="2">';
464: } else {
465: $line .= '<td>';
466: }
467: if ($can_delete) {
468: $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
469: }
470: if ($can_modify) {
1.219 raeburn 471: my $cat='<img class="LC_icon" alt="'.&mt('Metadata').'" title="'.&mt('Metadata').'" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').'" />';
1.152 albertel 472: my %anchor_fields = (
1.150 banghart 473: 'rename' => $filename,
474: currentpath => $current_path
475: );
1.188 bisitz 476: $line .= &make_anchor($url,\%anchor_fields,&mt('Rename'));
1.159 banghart 477: $line .= '</td><td>'.&make_anchor($href_edit_location.$filename.'.meta',\%anchor_fields,$cat);
1.150 banghart 478: # '<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
1.120 raeburn 479: }
480: $line .= '</td>';
1.77 banghart 481: }
1.61 banghart 482: }
1.124 albertel 483: my $curr_access;
484: if ($select_mode ne 'true') {
485: my $pub_access = 0;
486: my $guest_access = 0;
487: my $cond_access = 0;
488: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
489: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
490: if (($now > $start) && (!$end || $end > $now)) {
491: if ($scope eq 'public') {
492: $pub_access = 1;
493: } elsif ($scope eq 'guest') {
494: $guest_access = 1;
495: } else {
496: $cond_access = 1;
497: }
498: }
499: }
500: if (!$pub_access && !$guest_access && !$cond_access) {
501: $curr_access = &mt('Private');
502: } else {
503: my @allaccesses;
504: if ($pub_access) {
505: push(@allaccesses,&mt('Public'));
506: }
507: if ($guest_access) {
508: push(@allaccesses,&mt('Passphrase-protected'));
509: }
510: if ($cond_access) {
511: push(@allaccesses,&mt('Conditional'));
512: }
513: $curr_access = join('+ ',@allaccesses);
514: }
515: }
1.156 albertel 516: &display_directory_line($r,$select_mode, $filename, $mtime, $size, $css_class, $line,
517: \%access_controls, $curr_access,$now, $version_flag, $href_location,
1.140 banghart 518: $url, $current_path, $access_admin_text);
1.134 banghart 519: if ($show_versions) {
1.156 albertel 520: foreach my $dir_line (@{ $versioned{$fullpath} }) {
521: my ($v_filename,$dom,$testdir,$size,$mtime,$obs) =
522: @$dir_line;
1.143 banghart 523: $line = '<td colspan="2"> </td>';
1.156 albertel 524: &display_directory_line($r,$select_mode, $v_filename, $mtime, $size,
525: $css_class, $line, \%access_controls, $curr_access, $now,
526: undef, $href_location, $url, $current_path, $access_admin_text, 1);
1.140 banghart 527: }
1.134 banghart 528: }
1.47 banghart 529: }
530: }
531: }
1.77 banghart 532: if ($select_mode eq 'true') {
1.229 raeburn 533: $r->print(&Apache::loncommon::end_data_table());
534: if ($zerobyte) {
535: $r->print('<p class="LC_warning">'.&mt('[quant,_1,file] in list not selectable as file size is 0 bytes.',$zerobyte).'</p>');
536: }
537: $r->print('
1.127 albertel 538: <input type="hidden" name="continue" value="true" />
539: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
1.235 raeburn 540: <input type="hidden" name="symb" value="'.$env{'form.symb'}.'" />
1.127 albertel 541: <input type="hidden" name="mode" value="selectfile" />
1.198 bisitz 542: <p>
543: <input type="submit" name="submit" value="'.&mt('Select checked files, and continue selecting').'" /><br />
1.248 bisitz 544: <input type="button" name="doit" onclick="finishSelect();" value="'.&mt('Select checked files, and close window').'" />
1.198 bisitz 545: </p>
1.48 banghart 546: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77 banghart 547: </form>');
548: } else {
1.197 bisitz 549: $r->print(&Apache::loncommon::end_data_table());
1.120 raeburn 550: if ($can_delete) {
551: $r->print('
1.199 bisitz 552: <p>
1.196 schafran 553: <input type="submit" name="doit" value="'.&mt('Delete Selected').'" />'.
1.168 albertel 554: &Apache::loncommon::help_open_topic('Portfolio DeleteFile').'
1.199 bisitz 555: </p>
1.77 banghart 556: <input type="hidden" name="action" value="delete" />
557: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.120 raeburn 558: </form>'
559: );
560: }
1.77 banghart 561: }
1.47 banghart 562: }
1.72 banghart 563:
1.24 albertel 564: sub open_form {
1.94 raeburn 565: my ($r,$url)=@_;
1.65 banghart 566: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.102 raeburn 567: $r->print('<form name="portform" method="post" action="'.$url.'">');
1.24 albertel 568: $r->print('<input type="hidden" name="action" value="'.
1.82 albertel 569: $env{'form.action'}.'" />');
1.24 albertel 570: $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65 banghart 571: foreach (@files) {
572: $r->print('<input type="hidden" name="selectfile" value="'.
573: $_.'" />');
574: }
1.24 albertel 575: $r->print('<input type="hidden" name="currentpath" value="'.
1.82 albertel 576: $env{'form.currentpath'}.'" />');
1.24 albertel 577: }
578:
579: sub close_form {
1.137 albertel 580: my ($r,$url,$button_text)=@_;
1.108 raeburn 581: if (!defined($button_text)) {
582: $button_text = {
583: 'continue' => &mt('Continue'),
584: 'cancel' => &mt('Cancel'),
585: };
586: }
1.138 albertel 587: $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
1.137 albertel 588: $r->print(&group_form_data().'</p></form>');
1.112 albertel 589: $r->print('<form action="'.$url.'" method="post">
1.24 albertel 590: <p>
591: <input type="hidden" name="currentpath" value="'.
1.137 albertel 592: $env{'form.currentpath'}.'" />'.
593: &group_form_data());
1.108 raeburn 594: $r->print("\n".' <input type="submit" value="'.$button_text->{'cancel'}.'" />
1.94 raeburn 595: </p></form>');
1.24 albertel 596: }
597:
598: sub display_file {
1.27 albertel 599: my ($path,$filename)=@_;
1.65 banghart 600: my $display_file_text;
1.116 albertel 601: my $file_start='<span class="LC_filename">';
602: my $file_end='</span>';
1.82 albertel 603: if (!defined($path)) { $path=$env{'form.currentpath'}; }
1.65 banghart 604: if (!defined($filename)) {
1.82 albertel 605: $filename=$env{'form.selectfile'};
1.116 albertel 606: $display_file_text = $file_start.$path.$filename.$file_end;
1.65 banghart 607: } elsif (ref($filename) eq "ARRAY") {
1.116 albertel 608: foreach my $file (@$filename) {
609: $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
1.65 banghart 610: }
611: } elsif (ref($filename) eq "SCALAR") {
1.116 albertel 612: $display_file_text = $file_start.$path.$$filename.$file_end;
613: } else {
614: $display_file_text = $file_start.$path.$filename.$file_end;
1.65 banghart 615: }
616: return $display_file_text;
1.24 albertel 617: }
618:
619: sub done {
1.241 bisitz 620: my ($linktext,$url)=@_;
1.243 raeburn 621: unless (defined($linktext)) {
1.241 bisitz 622: $linktext='Return to directory';
1.76 banghart 623: }
1.153 banghart 624: my %anchor_fields = (
1.161 banghart 625: 'showversions' => $env{'form.showversions'},
1.153 banghart 626: 'currentpath' => $env{'form.currentpath'},
627: 'fieldname' => $env{'form.fieldname'},
1.235 raeburn 628: 'symb' => $env{'form.symb'},
1.153 banghart 629: 'mode' => $env{'form.mode'}
630: );
1.241 bisitz 631: my $result = &Apache::lonhtmlcommon::actionbox(
632: [&make_anchor($url,\%anchor_fields,&mt($linktext))]);
1.94 raeburn 633: return $result;
1.24 albertel 634: }
635:
636: sub delete {
1.191 raeburn 637: my ($r,$url,$group)=@_;
1.55 banghart 638: my @check;
1.82 albertel 639: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.138 albertel 640: $file_name = &prepend_group($file_name);
1.65 banghart 641: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.191 raeburn 642: my ($uname,$udom) = &get_name_dom($group);
1.94 raeburn 643: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.241 bisitz 644: $r->print(
645: '<p class="LC_warning">'
646: .&mt('The file is locked and cannot be deleted.')
647: .'</p>'
648: .&done(undef,$url)
649: );
1.55 banghart 650: } else {
1.66 banghart 651: if (scalar(@files)) {
1.94 raeburn 652: &open_form($r,$url);
1.188 bisitz 653: $r->print('<p>'.&mt('Delete [_1]?',&display_file(undef,\@files)).'</p>');
1.137 albertel 654: &close_form($r,$url);
1.66 banghart 655: } else {
1.237 bisitz 656: $r->print('<p class="LC_warning">'.&mt('No file was checked to delete.').'</p>');
1.137 albertel 657: $r->print(&done(undef,$url));
1.66 banghart 658: }
1.55 banghart 659: }
1.24 albertel 660: }
661:
662: sub delete_confirmed {
1.164 raeburn 663: my ($r,$url,$group)=@_;
1.65 banghart 664: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
665: my $result;
1.191 raeburn 666: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 667: my $port_path = &get_port_path();
1.164 raeburn 668: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
669: $uname);
1.241 bisitz 670: my @msg;
1.65 banghart 671: foreach my $delete_file (@files) {
1.241 bisitz 672: $result =
673: &Apache::lonnet::removeuserfile(
674: $uname,$udom,$port_path.
675: $env{'form.currentpath'}.
676: $delete_file);
1.65 banghart 677: if ($result ne 'ok') {
1.241 bisitz 678: push(@msg, &Apache::lonhtmlcommon::confirm_success(
679: &mt('An error occurred ([_1]) while trying to delete [_2].'
680: ,$result,&display_file(undef, $delete_file)),1));
681: } else {
682: push(@msg, &Apache::lonhtmlcommon::confirm_success(
683: &mt('File: [_1] deleted.'
684: ,&display_file(undef,$delete_file))));
1.164 raeburn 685: my $file_name = $env{'form.currentpath'}.$delete_file;
686: $file_name = &prepend_group($file_name);
687: my %access_controls =
688: &Apache::lonnet::get_access_controls($current_permissions,
689: $group,$file_name);
690: if (keys(%access_controls) > 0) {
691: my %changes;
1.166 raeburn 692: foreach my $key (keys(%{$access_controls{$file_name}})) {
1.164 raeburn 693: $changes{'delete'}{$key} = 1;
694: }
695: if (keys(%changes) > 0) {
696: my ($outcome,$deloutcome,$new_values,$translation) =
697: &Apache::lonnet::modify_access_controls($file_name,\%changes,
698: $udom,$uname);
699: if ($outcome ne 'ok') {
1.241 bisitz 700: push(@msg, &Apache::lonhtmlcommon::confirm_success(
701: &mt('An error occurred ([_1]) while '.
702: 'trying to delete access controls for the file.',$outcome),1));
1.164 raeburn 703: } else {
704: if ($deloutcome eq 'ok') {
1.241 bisitz 705: push(@msg, &mt('Access controls also deleted for the file.')); # FIXME: Does the user really need this message?
1.164 raeburn 706: } else {
1.241 bisitz 707: push(@msg, &Apache::lonhtmlcommon::confirm_success(
708: &mt('An error occurred ([_1]) while '.
709: 'trying to delete access controls for the file.'
710: ,$deloutcome),1));
1.164 raeburn 711: }
712: }
713: }
714: }
1.65 banghart 715: }
1.24 albertel 716: }
1.241 bisitz 717: $r->print(&Apache::loncommon::confirmwrapper(join('<br />',@msg)));
1.137 albertel 718: $r->print(&done(undef,$url));
1.24 albertel 719: }
720:
1.30 banghart 721: sub delete_dir {
1.137 albertel 722: my ($r,$url)=@_;
1.94 raeburn 723: &open_form($r,$url);
1.188 bisitz 724: $r->print('<p>'.&mt('Delete [_1]?',&display_file()).'</p>');
1.137 albertel 725: &close_form($r,$url);
1.30 banghart 726: }
727:
728: sub delete_dir_confirmed {
1.191 raeburn 729: my ($r,$url,$group)=@_;
1.82 albertel 730: my $directory_name = $env{'form.currentpath'};
1.81 albertel 731: $directory_name =~ s|/$||; # remove any trailing slash
1.191 raeburn 732: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 733: my $namespace = &get_namespace();
734: my $port_path = &get_port_path();
1.94 raeburn 735: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.30 banghart 736: $directory_name);
1.241 bisitz 737:
1.30 banghart 738: if ($result ne 'ok') {
1.241 bisitz 739: $r->print(
740: &Apache::loncommon::confirmwrapper(
741: &Apache::lonhtmlcommon::confirm_success(
742: &mt('An error occurred (dir) ([_1]) while trying to delete [_2].'
743: ,$result,$directory_name),1)));
744: $r->print(&done(undef,$url));
745: return;
1.32 banghart 746: } else {
1.41 banghart 747: # now remove from recent
1.94 raeburn 748: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
1.32 banghart 749: my @dirs = split m!/!, $directory_name;
750: $directory_name='/';
751: for (my $i=1; $i < (@dirs - 1); $i ++){
752: $directory_name .= $dirs[$i].'/';
753: }
1.82 albertel 754: $env{'form.currentpath'} = $directory_name;
1.30 banghart 755: }
1.241 bisitz 756: $r->print(
757: &Apache::loncommon::confirmwrapper(
758: &Apache::lonhtmlcommon::confirm_success(
759: &mt('Directory successfully deleted'))));
1.137 albertel 760: $r->print(&done(undef,$url));
1.30 banghart 761: }
762:
1.24 albertel 763: sub rename {
1.191 raeburn 764: my ($r,$url,$group)=@_;
1.82 albertel 765: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
1.191 raeburn 766: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 767: $file_name = &prepend_group($file_name);
1.94 raeburn 768: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.241 bisitz 769: $r->print(
770: '<p class="LC_error">'
771: .&mt('The file is locked and cannot be renamed.')
772: .'</p>'
773: );
1.137 albertel 774: $r->print(&done(undef,$url));
1.55 banghart 775: } else {
1.94 raeburn 776: &open_form($r,$url);
1.188 bisitz 777: $r->print('<p>'.&mt('Rename [_1] to [_2]?', &display_file()
1.204 raeburn 778: , '<input name="filenewname" type="text" size="50" />').'</p>');
1.137 albertel 779: &close_form($r,$url);
1.55 banghart 780: }
1.24 albertel 781: }
782:
783: sub rename_confirmed {
1.164 raeburn 784: my ($r,$url,$group)=@_;
1.82 albertel 785: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.191 raeburn 786: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 787: my $port_path = &get_port_path();
1.241 bisitz 788:
789: # Display warning in case of filename cleaning has changed the filename
790: if ($filenewname ne $env{'form.filenewname'}) {
791: $r->print(
792: '<p><span class="LC_warning">'
793: .&mt('Invalid characters')
794: .'</span><br />'
795: .&mt('The new filename was changed from [_1] to [_2].'
796: ,'<span class="LC_filename">'.&display_file('',$env{'form.filenewname'}).'</span>'
797: ,'<span class="LC_filename">'.&display_file('',$filenewname).'</span>')
798: .'</p>'
799: );
800:
801: }
802:
803: # Filename empty?
1.27 albertel 804: if ($filenewname eq '') {
1.241 bisitz 805: $r->print(
806: &Apache::loncommon::confirmwrapper(
807: &Apache::lonhtmlcommon::confirm_success(
808: &mt('Error: no valid filename was provided to rename to.'),1)));
809: $r->print(&done(undef,$url));
810: return;
1.27 albertel 811: }
1.241 bisitz 812:
813: # Rename the file
1.164 raeburn 814: my $chg_access;
1.27 albertel 815: my $result=
1.94 raeburn 816: &Apache::lonnet::renameuserfile($uname,$udom,
817: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
818: $port_path.$env{'form.currentpath'}.$filenewname);
1.164 raeburn 819: if ($result eq 'ok') {
820: $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
821: } else {
1.241 bisitz 822: $r->print(
823: &Apache::loncommon::confirmwrapper(
824: &Apache::lonhtmlcommon::confirm_success(
825: &mt('An error occurred ([_1]) while trying to rename [_2] to [_3].'
826: ,$result,&display_file(),&display_file('',$filenewname))
827: ,1)));
828: $r->print(&done(undef,$url));
1.164 raeburn 829: return;
1.27 albertel 830: }
1.164 raeburn 831: $r->print($chg_access);
1.241 bisitz 832: $r->print(
833: &Apache::loncommon::confirmwrapper(
834: &Apache::lonhtmlcommon::confirm_success(
835: &mt('File successfully renamed'))));
1.137 albertel 836: $r->print(&done(undef,$url));
1.27 albertel 837: }
1.102 raeburn 838:
1.164 raeburn 839: sub access_for_renamed {
840: my ($filenewname,$group,$udom,$uname) = @_;
841: my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'};
842: $oldfile = &prepend_group($oldfile);
843: my $newfile = $env{'form.currentpath'}.$filenewname;
844: $newfile = &prepend_group($newfile);
845: my $current_permissions =
1.165 albertel 846: &Apache::lonnet::get_portfile_permissions($udom,$uname);
1.164 raeburn 847: my %access_controls =
1.165 albertel 848: &Apache::lonnet::get_access_controls($current_permissions,
849: $group,$oldfile);
1.164 raeburn 850: my $chg_text;
851: if (keys(%access_controls) > 0) {
852: my %change_old;
853: my %change_new;
1.165 albertel 854: foreach my $key (keys(%{$access_controls{$oldfile}})) {
1.164 raeburn 855: $change_old{'delete'}{$key} = 1;
856: $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key};
857: }
858: my ($outcome,$deloutcome,$new_values,$translation) =
859: &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
1.165 albertel 860: $udom,$uname);
1.164 raeburn 861: if ($outcome ne 'ok') {
1.182 albertel 862: $chg_text ='<br /><br />'.&mt("An error occurred ([_1]) while ".
1.165 albertel 863: "trying to delete access control records for the old name.",$outcome).
1.164 raeburn 864: '</span><br />';
865: } else {
866: if ($deloutcome ne 'ok') {
1.165 albertel 867: $chg_text = '<br /><br /><span class="LC_error"><br />'.
1.182 albertel 868: &mt("An error occurred ([_1]) while ".
1.165 albertel 869: "trying to delete access control records for the old name.",$deloutcome).
870: '</span><br />';
1.164 raeburn 871: }
872: }
873: ($outcome,$deloutcome,$new_values,$translation) =
874: &Apache::lonnet::modify_access_controls($newfile,\%change_new,
875: $udom,$uname);
876: if ($outcome ne 'ok') {
1.165 albertel 877: $chg_text .= '<br /><br />'.
1.182 albertel 878: &mt("An error occurred ([_1]) while ".
1.165 albertel 879: "trying to update access control records for the new name.",$outcome).
1.164 raeburn 880: '</span><br />';
881: }
882: if ($chg_text eq '') {
883: $chg_text = '<br /><br />'.&mt('Access controls updated to reflect the name change.');
884: }
885: }
886: return $chg_text;
887: }
888:
1.104 raeburn 889: sub display_access {
1.170 raeburn 890: my ($r,$url,$group,$can_setacl,$port_path,$action) = @_;
1.191 raeburn 891: my ($uname,$udom) = &get_name_dom($group);
1.104 raeburn 892: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
1.138 albertel 893: $file_name = &prepend_group($file_name);
1.104 raeburn 894: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
895: $uname);
896: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
1.120 raeburn 897: my $aclcount = keys(%access_controls);
1.170 raeburn 898: my ($header,$info);
899: if ($action eq 'chgaccess') {
1.241 bisitz 900: $header =
901: '<h2>'
902: .&mt('Allowing others to retrieve file: [_1]'
903: ,'<span class="LC_filename">'
904: .$port_path.$env{'form.currentpath'}.$env{'form.access'}
905: .'</span>')
906: .'</h2>';
1.170 raeburn 907: $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.');
908: $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
909: $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
910: $info .= '</li><li>'.&explain_conditionals();
1.174 raeburn 911: $info .= '</li></ul>'.
1.201 raeburn 912: &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 913: if ($group eq '') {
1.210 weissno 914: $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 915: } else {
916: $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
917: }
1.201 raeburn 918: $info .= "<br /><a href=\"/adm/$udom/$uname/aboutme\">".&Apache::lonnet::absolute_url($ENV{'SERVER_NAME'})."/adm/$udom/$uname/aboutme</a><br />";
1.174 raeburn 919: if ($group ne '') {
1.253 raeburn 920: $info .= &mt("Users with course editing rights may add a 'Group Portfolio' item using the Course Editor (Collaboration tab), to provide access to viewable group portfolio files.").'<br />';
1.170 raeburn 921: }
922: } else {
923: $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'.
924: &explain_conditionals().'<br />';
1.142 raeburn 925: }
1.120 raeburn 926: if ($can_setacl) {
927: &open_form($r,$url);
928: $r->print($header.$info);
1.187 bisitz 929: $r->print('<br />'.&Apache::loncommon::help_open_topic('Portfolio ShareFile SetAccess', &mt('Help on setting up share access')));
930: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile ChangeSetting', &mt('Help on changing settings')));
931: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile StopAccess', &mt('Help on removing share access')));
1.170 raeburn 932: &access_setting_table($r,$url,$file_name,$access_controls{$file_name},
933: $action);
1.120 raeburn 934: my $button_text = {
1.108 raeburn 935: 'continue' => &mt('Proceed'),
1.188 bisitz 936: 'cancel' => &mt('Return to directory'),
1.108 raeburn 937: };
1.137 albertel 938: &close_form($r,$url,$button_text);
1.120 raeburn 939: } else {
940: $r->print($header);
941: if ($aclcount) {
942: $r->print($info);
943: }
1.137 albertel 944: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
1.120 raeburn 945: }
946: }
947:
1.170 raeburn 948: sub explain_conditionals {
949: return
1.254 raeburn 950: &mt('Conditional files are accessible to users who satisfy the conditions you set.').'<br /><ul>'.
951: '<li>'.&mt('Conditions can be IP-based, in which case no log-in is required').'</li>'.
952: '<li>'.&mt("Conditions can also be based on a user's status, in which case the user needs an account in the LON-CAPA network, and needs to be logged in.").'<br />'."\n".
953: &mt('The status-based conditions can include affiliation with a particular course or community, or a user account in a specific domain.').'<br />'."\n".
954: &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'</li></ul>';
1.170 raeburn 955: }
956:
1.120 raeburn 957: sub view_access_settings {
1.137 albertel 958: my ($r,$url,$access_controls,$aclcount) = @_;
1.120 raeburn 959: my ($showstart,$showend);
960: my %todisplay;
961: foreach my $key (sort(keys(%{$access_controls}))) {
962: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
963: $todisplay{$scope}{$key} = $$access_controls{$key};
964: }
965: if ($aclcount) {
1.188 bisitz 966: $r->print('<h4>'.&mt('Current access controls defined for this file:').'</h4>');
1.120 raeburn 967: $r->print(&Apache::loncommon::start_data_table());
968: $r->print(&Apache::loncommon::start_data_table_header_row());
969: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
970: '</th><th>'.&mt('Additional information').'</th>');
971: $r->print(&Apache::loncommon::end_data_table_header_row());
972: my $count = 1;
973: my $chg = 'none';
974: &build_access_summary($r,$count,$chg,%todisplay);
975: $r->print(&Apache::loncommon::end_data_table());
976: } else {
1.189 raeburn 977: $r->print(&mt('No access control settings currently exist for this file.').'<br />');
1.120 raeburn 978: }
1.153 banghart 979: my %anchor_fields = (
980: 'currentpath' => $env{'form.currentpath'}
981: );
1.188 bisitz 982: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory')));
1.120 raeburn 983: return;
1.104 raeburn 984: }
985:
1.120 raeburn 986: sub build_access_summary {
987: my ($r,$count,$chg,%todisplay) = @_;
988: my ($showstart,$showend);
989: my %scope_desc = (
990: public => 'Public',
991: guest => 'Passphrase-protected',
992: domains => 'Conditional: domain-based',
993: users => 'Conditional: user-based',
1.221 raeburn 994: course => 'Conditional: course/community-based',
1.254 raeburn 995: ip => 'Conditional: IP-based',
1.120 raeburn 996: );
1.254 raeburn 997: my @allscopes = ('public','guest','domains','users','course','ip');
1.120 raeburn 998: foreach my $scope (@allscopes) {
999: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
1000: next;
1001: }
1002: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
1003: if ($count) {
1004: $r->print(&Apache::loncommon::start_data_table_row());
1005: }
1006: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1007: my $content = $todisplay{$scope}{$key};
1008: if ($chg eq 'delete') {
1009: $showstart = &mt('Deleted');
1010: $showend = $showstart;
1011: } else {
1.236 bisitz 1012: $showstart = &Apache::lonlocal::locallocaltime($start);
1.120 raeburn 1013: if ($end == 0) {
1014: $showend = &mt('No end date');
1015: } else {
1.236 bisitz 1016: $showend = &Apache::lonlocal::locallocaltime($end);
1.120 raeburn 1017: }
1018: }
1019: $r->print('<td>'.&mt($scope_desc{$scope}));
1.221 raeburn 1020: my $crstype;
1.170 raeburn 1021: if ($scope eq 'course') {
1.120 raeburn 1022: if ($chg ne 'delete') {
1023: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1024: my %course_description = &Apache::lonnet::coursedescription($cid);
1025: $r->print('<br />('.$course_description{'description'}.')');
1.221 raeburn 1026: $crstype = 'Course';
1027: if ($course_description{'type'} ne '') {
1028: $crstype = $course_description{'type'};
1029: }
1.120 raeburn 1030: }
1031: }
1032: $r->print('</td><td>'.&mt('Start: ').$showstart.
1033: '<br />'.&mt('End: ').$showend.'</td><td>');
1034: if ($chg ne 'delete') {
1035: if ($scope eq 'guest') {
1036: $r->print(&mt('Passphrase').': '.$content->{'password'});
1.170 raeburn 1037: } elsif ($scope eq 'course') {
1.172 raeburn 1038: $r->print('<table width="100%"><tr>');
1.120 raeburn 1039: $r->print('<th>'.&mt('Roles').'</th><th>'.
1040: &mt('Access').'</th><th>'.
1041: &mt('Sections').'</th>');
1.170 raeburn 1042: $r->print('<th>'.&mt('Groups').'</th>');
1.120 raeburn 1043: $r->print('</tr>');
1044: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
1045: $r->print('<tr>');
1046: foreach my $item ('role','access','section','group') {
1047: $r->print('<td>');
1048: if ($item eq 'role') {
1049: my $role_output;
1050: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
1051: if ($role eq 'all') {
1052: $role_output .= $role.',';
1053: } elsif ($role =~ /^cr/) {
1054: $role_output .= (split('/',$role))[3].',';
1055: } else {
1.221 raeburn 1056: $role_output .= &Apache::lonnet::plaintext($role,$crstype).',';
1.120 raeburn 1057: }
1058: }
1059: $role_output =~ s/,$//;
1060: $r->print($role_output);
1061: } else {
1062: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
1063: }
1.170 raeburn 1064: $r->print('</td>');
1.120 raeburn 1065: }
1.170 raeburn 1066: $r->print('</tr>');
1.120 raeburn 1067: }
1.170 raeburn 1068: $r->print('</table>');
1.120 raeburn 1069: } elsif ($scope eq 'domains') {
1070: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
1071: } elsif ($scope eq 'users') {
1072: my $curr_user_list = &sort_users($content->{'users'});
1073: $r->print(&mt('Users: ').$curr_user_list);
1.254 raeburn 1074: } elsif ($scope eq 'ip') {
1075: my $curr_ips_list = &sort_ips($content->{'ip'});
1.258 ! raeburn 1076: $r->print(&mt('IP(s):').' '.$curr_ips_list);
1.120 raeburn 1077: } else {
1078: $r->print(' ');
1079: }
1080: } else {
1081: $r->print(' ');
1082: }
1083: $r->print('</td>');
1084: $r->print(&Apache::loncommon::end_data_table_row());
1085: $count ++;
1086: }
1087: }
1088: }
1089:
1090:
1.104 raeburn 1091: sub update_access {
1.137 albertel 1092: my ($r,$url,$group,$port_path) = @_;
1.104 raeburn 1093: my $totalprocessed = 0;
1094: my %processing;
1095: my %title = (
1.108 raeburn 1096: 'activate' => 'New control(s) added',
1097: 'delete' => 'Existing control(s) deleted',
1098: 'update' => 'Existing control(s) modified',
1.104 raeburn 1099: );
1.108 raeburn 1100: my $changes;
1.104 raeburn 1101: foreach my $chg (sort(keys(%title))) {
1102: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
1103: $totalprocessed += @{$processing{$chg}};
1104: foreach my $num (@{$processing{$chg}}) {
1105: my $scope = $env{'form.scope_'.$num};
1106: my ($start,$end) = &get_dates_from_form($num);
1107: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
1108: if ($chg eq 'delete') {
1109: $$changes{$chg}{$newkey} = 1;
1110: } else {
1111: $$changes{$chg}{$newkey} =
1.108 raeburn 1112: &build_access_record($num,$scope,$start,$end,$chg);
1.104 raeburn 1113: }
1114: }
1115: }
1116: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.241 bisitz 1117: $r->print('<h2>'.&mt('Allowing others to retrieve file: [_1]',
1118: '<span class="LC_filename">'.$port_path.$file_name.'</span>').'</h2>'."\n");
1.138 albertel 1119: $file_name = &prepend_group($file_name);
1.191 raeburn 1120: my ($uname,$udom) = &get_name_dom($group);
1.104 raeburn 1121: my ($errors,$outcome,$deloutcome,$new_values,$translation);
1122: if ($totalprocessed) {
1123: ($outcome,$deloutcome,$new_values,$translation) =
1.108 raeburn 1124: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
1125: $uname);
1.104 raeburn 1126: }
1.108 raeburn 1127: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1128: $uname);
1.109 albertel 1129: my %access_controls =
1130: &Apache::lonnet::get_access_controls($current_permissions,
1131: $group,$file_name);
1.104 raeburn 1132: if ($totalprocessed) {
1133: if ($outcome eq 'ok') {
1134: my $updated_controls = $access_controls{$file_name};
1135: my ($showstart,$showend);
1136: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1137: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1138: $r->print('<th>'.&mt('Type of change').'</th><th>'.
1139: &mt('Access control').'</th><th>'.&mt('Dates available').
1140: '</th><th>'.&mt('Additional information').'</th>');
1.110 albertel 1141: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 1142: foreach my $chg (sort(keys(%processing))) {
1143: if (@{$processing{$chg}} > 0) {
1144: if ($chg eq 'delete') {
1145: if (!($deloutcome eq 'ok')) {
1.116 albertel 1146: $errors .='<span class="LC_error">'.
1147: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
1148: '</span>';
1.104 raeburn 1149: next;
1150: }
1151: }
1152: my $numchgs = @{$processing{$chg}};
1153: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1154: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
1155: '.</td>');
1.104 raeburn 1156: my $count = 0;
1.120 raeburn 1157: my %todisplay;
1.104 raeburn 1158: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
1.120 raeburn 1159: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.104 raeburn 1160: my $newkey = $key;
1161: if ($chg eq 'activate') {
1162: $newkey =~ s/^(\d+)/$$translation{$1}/;
1163: }
1.120 raeburn 1164: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
1.104 raeburn 1165: }
1.120 raeburn 1166: &build_access_summary($r,$count,$chg,%todisplay);
1.104 raeburn 1167: }
1168: }
1169: $r->print(&Apache::loncommon::end_data_table());
1170: } else {
1171: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
1.116 albertel 1172: $errors .= '<span class="LC_error">'.
1.179 albertel 1173: &mt('A problem occurred saving access control settings: [_1]',$outcome).
1.116 albertel 1174: '</span>';
1.104 raeburn 1175: }
1176: }
1177: if ($errors) {
1178: $r->print($errors);
1179: }
1180: }
1.108 raeburn 1181: my $allnew = 0;
1182: my $totalnew = 0;
1183: my $status = 'new';
1184: my ($firstitem,$lastitem);
1.254 raeburn 1185: my @types = ('course','domains','users','ip');
1.221 raeburn 1186: foreach my $newitem (@types) {
1.108 raeburn 1187: $allnew += $env{'form.new'.$newitem};
1188: }
1189: if ($allnew > 0) {
1190: my $now = time;
1191: my $then = $now + (60*60*24*180); # six months approx.
1.138 albertel 1192: &open_form($r,$url);
1.249 bisitz 1193: my %showtypes = (
1.221 raeburn 1194: course => 'course/community',
1195: domains => 'domain',
1196: users => 'user',
1.254 raeburn 1197: ip => 'IP',
1.221 raeburn 1198: );
1199: foreach my $newitem (@types) {
1.249 bisitz 1200: next if ($env{'form.new'.$newitem} <= 0);
1201: $r->print(
1202: '<p>'
1203: .&mt('Add new [_1]'.$showtypes{$newitem}.'-based[_2] access control for portfolio file: [_3]',
1204: '<b>','</b>',
1205: '<span class="LC_filename"><b>'
1206: .$env{'form.currentpath'}.$env{'form.selectfile'}.'</b></span>')
1207: .'</p>');
1208: $firstitem = $totalnew;
1209: $lastitem = $totalnew + $env{'form.new'.$newitem};
1210: $totalnew = $lastitem;
1211: my @numbers;
1212: for (my $i=$firstitem; $i<$lastitem; $i++) {
1213: push(@numbers,$i);
1.108 raeburn 1214: }
1.249 bisitz 1215: &display_access_row($r,$status,$newitem,\@numbers,
1216: $access_controls{$file_name},$now,$then);
1.108 raeburn 1217: }
1.137 albertel 1218: &close_form($r,$url);
1.108 raeburn 1219: } else {
1.153 banghart 1220: my %anchor_fields = (
1221: 'currentpath' => $env{'form.currentpath'},
1222: 'access' => $env{'form.selectfile'}
1223: );
1.241 bisitz 1224: my @actions;
1225: push(@actions, &make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
1.153 banghart 1226: delete $anchor_fields{'access'};
1.241 bisitz 1227: push(@actions, &make_anchor($url,\%anchor_fields,&mt('Return to directory')));
1228: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(\@actions));
1.108 raeburn 1229: }
1.104 raeburn 1230: return;
1231: }
1232:
1233: sub build_access_record {
1.108 raeburn 1234: my ($num,$scope,$start,$end,$chg) = @_;
1.109 albertel 1235: my $record = {
1236: type => $scope,
1237: time => {
1238: start => $start,
1239: end => $end
1240: },
1241: };
1242:
1243: if ($scope eq 'guest') {
1244: $record->{'password'} = $env{'form.password'};
1.170 raeburn 1245: } elsif ($scope eq 'course') {
1.109 albertel 1246: $record->{'domain'} = $env{'form.crsdom_'.$num};
1247: $record->{'number'} = $env{'form.crsnum_'.$num};
1.108 raeburn 1248: my @role_ids;
1.109 albertel 1249: my @delete_role_ids =
1250: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
1251: my @preserves =
1252: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
1253: if (@delete_role_ids) {
1254: foreach my $id (@preserves) {
1255: if (grep {$_ = $id} (@delete_role_ids)) {
1256: next;
1257: }
1258: push(@role_ids,$id);
1259: }
1260: } else {
1261: push(@role_ids,@preserves);
1262: }
1263:
1264: my $next_id = $env{'form.add_role_'.$num};
1265: if ($next_id) {
1266: push(@role_ids,$next_id);
1267: }
1268:
1.108 raeburn 1269: foreach my $id (@role_ids) {
1270: my (@roles,@accesses,@sections,@groups);
1271: if (($id == $next_id) && ($chg eq 'update')) {
1.109 albertel 1272: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1.108 raeburn 1273: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
1274: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1.109 albertel 1275: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1.108 raeburn 1276: } else {
1277: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
1278: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
1279: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
1280: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
1281: }
1.109 albertel 1282: $record->{'roles'}{$id}{'role'} = \@roles;
1283: $record->{'roles'}{$id}{'access'} = \@accesses;
1284: $record->{'roles'}{$id}{'section'} = \@sections;
1285: $record->{'roles'}{$id}{'group'} = \@groups;
1.108 raeburn 1286: }
1287: } elsif ($scope eq 'domains') {
1288: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1.109 albertel 1289: $record->{'dom'} = \@doms;
1.108 raeburn 1290: } elsif ($scope eq 'users') {
1291: my $userlist = $env{'form.users_'.$num};
1.109 albertel 1292: $userlist =~ s/\s+//sg;
1293: my %userhash = map { ($_,1) } (split(/,/,$userlist));
1294: foreach my $user (keys(%userhash)) {
1.108 raeburn 1295: my ($uname,$udom) = split(/:/,$user);
1.109 albertel 1296: push(@{$record->{'users'}}, {
1297: 'uname' => $uname,
1298: 'udom' => $udom
1299: });
1300: }
1.254 raeburn 1301: } elsif ($scope eq 'ip') {
1302: my $ipslist = $env{'form.ips_'.$num};
1303: $ipslist =~ s/\s+//sg;
1304: my %ipshash = map { ($_,1) } (split(/,/,$ipslist));
1305: foreach my $ip (keys(%ipshash)) {
1306: push(@{$record->{'ip'}},$ip);
1307: }
1.108 raeburn 1308: }
1.104 raeburn 1309: return $record;
1310: }
1311:
1312: sub get_dates_from_form {
1313: my ($id) = @_;
1314: my $startdate;
1315: my $enddate;
1316: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
1317: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
1318: if ( exists ($env{'form.noend_'.$id}) ) {
1319: $enddate = 0;
1320: }
1321: return ($startdate,$enddate);
1322: }
1323:
1.108 raeburn 1324: sub sort_users {
1.109 albertel 1325: my ($users) = @_;
1326: my @curr_users = map {
1327: $_->{'uname'}.':'.$_->{'udom'}
1328: } (@{$users});
1329: my $curr_user_list = join(",\n",sort(@curr_users));
1.108 raeburn 1330: return $curr_user_list;
1331: }
1332:
1.254 raeburn 1333: sub sort_ips {
1334: my ($ips) = @_;
1335: if (ref($ips) eq 'ARRAY') {
1336: return join(",\n",sort(@{$ips}));
1337: }
1338: }
1339:
1.104 raeburn 1340: sub access_setting_table {
1.170 raeburn 1341: my ($r,$url,$filename,$access_controls,$action) = @_;
1.104 raeburn 1342: my ($public,$publictext);
1.170 raeburn 1343: $publictext ='Off';
1.104 raeburn 1344: my ($guest,$guesttext);
1.170 raeburn 1345: $guesttext = 'Off';
1.104 raeburn 1346: my @courses = ();
1347: my @domains = ();
1348: my @users = ();
1.254 raeburn 1349: my @ips = ();
1.104 raeburn 1350: my $now = time;
1351: my $then = $now + (60*60*24*180); # six months approx.
1.108 raeburn 1352: my ($num,$scope,$publicnum,$guestnum);
1.170 raeburn 1353: my (%acl_count,%end,%start,%conditionals);
1.104 raeburn 1354: foreach my $key (sort(keys(%{$access_controls}))) {
1.108 raeburn 1355: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1.104 raeburn 1356: if ($scope eq 'public') {
1357: $public = $key;
1.108 raeburn 1358: $publicnum = $num;
1359: $publictext = &acl_status($start{$key},$end{$key},$now);
1360: } elsif ($scope eq 'guest') {
1361: $guest=$key;
1362: $guestnum = $num;
1363: $guesttext = &acl_status($start{$key},$end{$key},$now);
1.170 raeburn 1364: } else {
1365: $conditionals{$scope}{$key} = $$access_controls{$key};
1366: if ($scope eq 'course') {
1367: push(@courses,$key);
1368: } elsif ($scope eq 'domains') {
1369: push(@domains,$key);
1370: } elsif ($scope eq 'users') {
1371: push(@users,$key);
1.254 raeburn 1372: } elsif ($scope eq 'ip') {
1373: push(@ips,$key);
1.170 raeburn 1374: }
1.104 raeburn 1375: }
1.108 raeburn 1376: $acl_count{$scope} ++;
1.104 raeburn 1377: }
1.108 raeburn 1378: $r->print('<table border="0"><tr><td valign="top">');
1.170 raeburn 1379: if ($action eq 'chgaccess') {
1380: &standard_settings($r,$now,$then,$url,$filename,\%acl_count,\%start,
1381: \%end,$public,$publicnum,$publictext,$guest,$guestnum,
1382: $guesttext,$access_controls,%conditionals);
1383: } else {
1384: &condition_setting($r,$access_controls,$now,$then,\%acl_count,
1.254 raeburn 1385: \@domains,\@users,\@courses,\@ips);
1.170 raeburn 1386: }
1387: $r->print('</td></tr></table>');
1388: }
1389:
1390: sub standard_settings {
1391: my ($r,$now,$then,$url,$filename,$acl_count,$start,$end,$public,$publicnum,
1392: $publictext,$guest,$guestnum,$guesttext,$access_controls,%conditionals)=@_;
1.187 bisitz 1393: $r->print('<h3>'.&mt('Public access: [_1]',&mt($publictext)).'</h3>');
1.104 raeburn 1394: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1395: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1396: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1.110 albertel 1397: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 1398: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1399: if ($public) {
1400: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
1.170 raeburn 1401: &dateboxes($publicnum,$start->{$public},$end->{$public}).'</td>');
1.108 raeburn 1402: } else {
1403: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
1404: &dateboxes('0',$now,$then).'</td>');
1405: }
1406: $r->print(&Apache::loncommon::end_data_table_row());
1407: $r->print(&Apache::loncommon::end_data_table());
1408: $r->print('</td><td width="40"> </td><td valign="top">');
1.187 bisitz 1409: $r->print('<h3>'.&mt('Passphrase-protected access: [_1]',&mt($guesttext)).'</h3>');
1.104 raeburn 1410: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1411: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1412: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1.120 raeburn 1413: '</th><th>'. &mt('Passphrase').'</th>');
1.110 albertel 1414: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1415: $r->print(&Apache::loncommon::start_data_table_row());
1416: my $passwd;
1417: if ($guest) {
1.109 albertel 1418: $passwd = $$access_controls{$guest}{'password'};
1.108 raeburn 1419: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1.170 raeburn 1420: &dateboxes($guestnum,$start->{$guest},$end->{$guest}).'</td>');
1.108 raeburn 1421: } else {
1422: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1423: &dateboxes('1',$now,$then).'</td>');
1.104 raeburn 1424: }
1.108 raeburn 1425: $r->print('<td><input type="text" size="15" name="password" value="'.
1426: $passwd.'" /></td>');
1.104 raeburn 1427: $r->print(&Apache::loncommon::end_data_table_row());
1428: $r->print(&Apache::loncommon::end_data_table());
1.170 raeburn 1429: $r->print('</td></tr><tr><td colspan="3"> </td></tr>'.
1.254 raeburn 1430: '<tr><td colspan="3" valign="top">');
1.170 raeburn 1431: my $numconditionals = 0;
1432: my $conditionstext;
1433: my %cond_status;
1.254 raeburn 1434: foreach my $scope ('domains','users','course','ip') {
1.170 raeburn 1435: $numconditionals += $acl_count->{$scope};
1436: if ($acl_count->{$scope} > 0) {
1.254 raeburn 1437: if ($conditionstext ne 'Active') {
1.170 raeburn 1438: foreach my $key (keys(%{$conditionals{$scope}})) {
1439: $conditionstext = &acl_status($start->{$key},$end->{$key},$now);
1440: if ($conditionstext eq 'Active') {
1441: last;
1442: }
1443: }
1444: }
1445: }
1446: }
1447: if ($conditionstext eq '') {
1448: $conditionstext = 'Off';
1449: }
1450: my %anchor_fields = (
1451: 'access' => $env{'form.selectfile'},
1452: 'action' => 'chgconditions',
1453: 'currentpath' => $env{'form.currentpath'},
1454: );
1.187 bisitz 1455: $r->print('<h3>'.&mt('Conditional access: [_1]',&mt($conditionstext)).'</h3>');
1.170 raeburn 1456: if ($numconditionals > 0) {
1457: my $count = 1;
1458: my $chg = 'none';
1459: $r->print(&mt('You have previously set [_1] conditional access controls.',$numconditionals).' '.&make_anchor($url,\%anchor_fields,&mt('Change Conditions')).'<br /><br />');
1460: $r->print(&Apache::loncommon::start_data_table());
1461: $r->print(&Apache::loncommon::start_data_table_header_row());
1462: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
1463: '</th><th>'.&mt('Additional information').'</th>');
1464: $r->print(&Apache::loncommon::end_data_table_header_row());
1465: &build_access_summary($r,$count,$chg,%conditionals);
1466: $r->print(&Apache::loncommon::end_data_table());
1467: } else {
1.254 raeburn 1468: $r->print(&make_anchor($url,\%anchor_fields,&mt('Add conditional access')).' '.&mt("based on domain, username, course/community affiliation or user's IP address."));
1.170 raeburn 1469: }
1470: }
1471:
1472: sub condition_setting {
1.254 raeburn 1473: my ($r,$access_controls,$now,$then,$acl_count,$domains,$users,$courses,$ips) = @_;
1.170 raeburn 1474: $r->print('<tr><td valign="top">');
1475: &access_element($r,'domains',$acl_count,$domains,$access_controls,$now,$then);
1.158 albertel 1476: $r->print('</td><td> </td><td valign="top">');
1.170 raeburn 1477: &access_element($r,'users',$acl_count,$users,$access_controls,$now,$then);
1.254 raeburn 1478: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr><td valign="top">');
1.170 raeburn 1479: &access_element($r,'course',$acl_count,$courses,$access_controls,$now,$then);
1.254 raeburn 1480: $r->print('</td><td> </td><td valign="top">');
1481: &access_element($r,'ip',$acl_count,$ips,$access_controls,$now,$then);
1.108 raeburn 1482: $r->print('</td></tr></table>');
1483: }
1484:
1485: sub acl_status {
1486: my ($start,$end,$now) = @_;
1487: if ($start > $now) {
1.170 raeburn 1488: return 'Inactive';
1.108 raeburn 1489: }
1490: if ($end && $end<$now) {
1.170 raeburn 1491: return 'Inactive';
1.108 raeburn 1492: }
1.170 raeburn 1493: return 'Active';
1.108 raeburn 1494: }
1495:
1496: sub access_element {
1497: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1.249 bisitz 1498: my %typetext = (
1.221 raeburn 1499: domains => 'Domain',
1500: users => 'User',
1.254 raeburn 1501: course => 'Course/Community',
1502: ip => 'IP',
1.221 raeburn 1503: );
1.249 bisitz 1504: $r->print('<h3>'.&mt($typetext{$type}.'-based conditional access:').' ');
1.108 raeburn 1505: if ($$acl_count{$type}) {
1.249 bisitz 1506: $r->print(&mt('[quant,_1,condition]',$$acl_count{$type}));
1.108 raeburn 1507: } else {
1508: $r->print(&mt('Off'));
1509: }
1510: $r->print('</h3>');
1511: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1512: return;
1513: }
1514:
1515: sub display_access_row {
1516: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1.249 bisitz 1517: my ($showtype, $infotype);
1.221 raeburn 1518: if ($type eq 'course') {
1519: $showtype = &mt('Courses/Communities');
1.249 bisitz 1520: $infotype = 'Course/Community';
1.221 raeburn 1521: } elsif ($type eq 'domains') {
1522: $showtype = &mt('Domains');
1.249 bisitz 1523: $infotype = 'Domain';
1.221 raeburn 1524: } elsif ($type eq 'users') {
1525: $showtype = &mt('Users');
1.249 bisitz 1526: $infotype = 'User';
1.254 raeburn 1527: } elsif ($type eq 'ip') {
1528: $showtype = &mt('IP-based');
1529: $infotype = 'IP';
1.221 raeburn 1530: }
1.108 raeburn 1531: if (@{$items} > 0) {
1532: my @all_doms;
1533: my $colspan = 3;
1534: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1535: $r->print(&Apache::loncommon::start_data_table_header_row());
1.221 raeburn 1536: $r->print('<th>'.&mt('Action?').'</th><th>'.$showtype.'</th><th>'.
1.108 raeburn 1537: &mt('Dates available').'</th>');
1.172 raeburn 1538: if ($type eq 'course' && $status eq 'old') {
1.221 raeburn 1539: $r->print('<th>'.&mt('Allowed course/community affiliations').
1.108 raeburn 1540: '</th>');
1541: $colspan ++;
1542: } elsif ($type eq 'domains') {
1.178 albertel 1543: @all_doms = sort(&Apache::lonnet::all_domains());
1.108 raeburn 1544: }
1.110 albertel 1545: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1546: foreach my $key (@{$items}) {
1.118 albertel 1547: $r->print(&Apache::loncommon::start_data_table_row());
1.170 raeburn 1548: if ($type eq 'course') {
1.118 albertel 1549: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1.108 raeburn 1550: } elsif ($type eq 'domains') {
1551: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1552: $then);
1553: } elsif ($type eq 'users') {
1554: &users_row($r,$status,$key,$access_controls,$now,$then);
1.254 raeburn 1555: } elsif ($type eq 'ip') {
1556: &ips_row($r,$status,$key,$access_controls,$now,$then);
1.108 raeburn 1557: }
1.118 albertel 1558: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1559: }
1560: if ($status eq 'old') {
1.111 albertel 1561: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1562: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1563: '</td>');
1.111 albertel 1564: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1565: }
1566: $r->print(&Apache::loncommon::end_data_table());
1567: } else {
1.249 bisitz 1568: $r->print(
1569: '<p class="LC_info">'
1570: .&mt('No '.$infotype.'-based conditions defined')
1571: .'</p>'
1572: .&additional_item($type)
1573: );
1.108 raeburn 1574: }
1575: return;
1576: }
1577:
1.110 albertel 1578: sub course_js {
1579: return qq|
1.108 raeburn 1580: <script type="text/javascript">
1.249 bisitz 1581: // <![CDATA[
1.172 raeburn 1582: function setRoleOptions(num,roleid,cdom,cnum,type) {
1583: updateIndexNum = getIndexByValue('update',num);
1584: var addItem = 'add_role_'+num;
1585: var addIndexNum = getIndexByName(addItem);
1586: if (document.portform.elements[addItem].checked) {
1587: document.portform.elements[updateIndexNum].checked = true;
1588: var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1.108 raeburn 1589: var title = 'Roles_Chooser';
1590: var options = 'scrollbars=1,resizable=1,menubar=0';
1591: options += ',width=700,height=600';
1592: rolebrowser = open(url,title,options,'1');
1593: rolebrowser.focus();
1594: } else {
1.172 raeburn 1595: addArray = new Array ('role','access','section','group');
1596: for (var j=0;j<addArray.length;j++) {
1597: var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid);
1598: document.portform.elements[itemIndex].value = '';
1.108 raeburn 1599: }
1600: }
1601: }
1602:
1.172 raeburn 1603: function getIndexByName(item) {
1.108 raeburn 1604: for (var i=0;i<document.portform.elements.length;i++) {
1.172 raeburn 1605: if (document.portform.elements[i].name == item) {
1.108 raeburn 1606: return i;
1607: }
1608: }
1609: return -1;
1610: }
1611:
1.172 raeburn 1612: function getIndexByValue(name,value) {
1.108 raeburn 1613: for (var i=0;i<document.portform.elements.length;i++) {
1614: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1615: return i;
1616: }
1617: }
1618: return -1;
1619: }
1620:
1.249 bisitz 1621: // ]]>
1.108 raeburn 1622: </script>
1.110 albertel 1623: |;
1624: }
1625:
1626: sub course_row {
1.118 albertel 1627: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1.115 raeburn 1628: my $content;
1.110 albertel 1629: my $defdom = $env{'user.domain'};
1630: if ($status eq 'old') {
1.115 raeburn 1631: $content = $$access_controls{$item};
1632: $defdom = $content->{'domain'};
1.110 albertel 1633: }
1634: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1635: .&course_js();
1.221 raeburn 1636: my $showtype = &mt('Course/Community');
1637: my $crstype = 'Course';
1.108 raeburn 1638: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1639: $type);
1.110 albertel 1640: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1.108 raeburn 1641: if ($status eq 'old') {
1.115 raeburn 1642: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 1643: my %course_description = &Apache::lonnet::coursedescription($cid);
1.221 raeburn 1644: if ($course_description{'type'} ne '') {
1645: $crstype = $course_description{'type'};
1646: }
1.115 raeburn 1647: $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 1648: } elsif ($status eq 'new') {
1.221 raeburn 1649: $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$showtype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
1.108 raeburn 1650: }
1.172 raeburn 1651: $r->print('<td>'.&dateboxes($num,$start,$end));
1652: my $newrole_id = 1;
1.108 raeburn 1653: if ($status eq 'old') {
1.172 raeburn 1654: $r->print('</td><td>');
1.108 raeburn 1655: my $max_id = 0;
1.172 raeburn 1656: if (keys(%{$content->{'roles'}}) > 0) {
1657: $r->print('<table><tr><th>'.&mt('Action').'</th>'.
1658: '<th>'.&mt('Roles').'</th>'.
1659: '<th>'.&mt('Access').'</th>'.
1660: '<th>'.&mt('Sections').'</th>'.
1661: '<th>'.&mt('Groups').'</th></tr>');
1662: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1663: if ($role_id > $max_id) {
1664: $max_id = $role_id;
1665: }
1666: $max_id ++;
1.221 raeburn 1667: my $role_selects = &role_selectors($num,$role_id,$crstype,$content,'display');
1.200 bisitz 1668: $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 1669: }
1670: $r->print('</table>');
1671: }
1672: $r->print('<br />'.&mt('Add a roles-based condition').
1.214 bisitz 1673: ' <input type="checkbox" name="add_role_'.
1.248 bisitz 1674: $num.'" onclick="javascript:setRoleOptions('."'$num',
1.172 raeburn 1675: '$max_id','$content->{'domain'}','$content->{'number'}',
1.221 raeburn 1676: '$showtype'".')" value="" />');
1.172 raeburn 1677: $newrole_id = $max_id;
1678: } else {
1.214 bisitz 1679: $r->print('<input type="hidden" name="add_role_'.$num.'" value="" />');
1.108 raeburn 1680: }
1.172 raeburn 1681: $r->print(&add_course_role($num,$newrole_id));
1682: $r->print('</td>');
1.108 raeburn 1683: return;
1684: }
1685:
1.172 raeburn 1686: sub add_course_role {
1687: my ($num,$max_id) = @_;
1688: my $output;
1689: $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'.
1690: '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'.
1691: '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'.
1692: '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />';
1693: return $output;
1694: }
1695:
1.108 raeburn 1696: sub domains_row {
1697: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1698: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1699: 'domains');
1.207 bisitz 1700: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="multiple">'.
1.108 raeburn 1701: ' <option value="">'.&mt('Please select').'</option>';
1702: if ($status eq 'old') {
1.109 albertel 1703: my $content = $$access_controls{$item};
1704: foreach my $dom (@{$all_doms}) {
1705: if ((@{$content->{'dom'}} > 0)
1706: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.214 bisitz 1707: $dom_select .= '<option value="'.$dom.'" selected="selected">'.
1.108 raeburn 1708: $dom.'</option>';
1709: } else {
1710: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1711: }
1712: }
1713: } else {
1714: foreach my $dom (@{$all_doms}) {
1715: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1716: }
1717: }
1.112 albertel 1718: $dom_select .= '</select>';
1.108 raeburn 1719: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1720: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1721: }
1722:
1723: sub users_row {
1724: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1725: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1726: 'users');
1727: my $curr_user_list;
1728: if ($status eq 'old') {
1.109 albertel 1729: my $content = $$access_controls{$item};
1730: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1731: }
1732: $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>');
1733: }
1734:
1.254 raeburn 1735: sub ips_row {
1736: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1737: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1738: 'ip');
1739: my $curr_ips_list;
1740: if ($status eq 'old') {
1741: my $content = $$access_controls{$item};
1742: $curr_ips_list = &sort_ips($content->{'ip'});
1743: }
1744: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt('Format for IP controls').'<br />'.
1745: &mt('[_1] or [_2] or [_3] or [_4] or [_5]','<tt>35.8.*</tt>','<tt>35.8.3.[34-56]</tt>',
1746: '<tt>*.msu.edu</tt>','<tt>35.8.3.34</tt>','<tt>somehostname.pa.msu.edu</tt>').'<br />'.
1747: &mt('Use a comma to separate different ranges.').'</br/>'.
1748: '<textarea name="ips_'.$num.'" cols="30" rows="5">'.$curr_ips_list.'</textarea></td>'.
1749: '<td>'.&dateboxes($num,$start,$end).'</td>');
1750: }
1751:
1.108 raeburn 1752: sub additional_item {
1753: my ($type) = @_;
1.221 raeburn 1754: my $showtype;
1755: if ($type eq 'course') {
1.249 bisitz 1756: $showtype = 'course/community';
1.221 raeburn 1757: } elsif ($type eq 'domains') {
1.249 bisitz 1758: $showtype = 'domain';
1.221 raeburn 1759: } elsif ($type eq 'users') {
1.249 bisitz 1760: $showtype = 'user';
1.254 raeburn 1761: } elsif ($type eq 'ip') {
1762: $showtype = 'IP';
1.221 raeburn 1763: }
1.249 bisitz 1764: return
1765: &mt('Add new '.$showtype.'-based condition(s)?')
1766: .' '.&mt('Number to add: ')
1767: .'<input type="text" name="new'.$type.'" size="3" value="0" />';
1.108 raeburn 1768: }
1769:
1770: sub actionbox {
1771: my ($status,$num,$scope) = @_;
1.200 bisitz 1772: my $output = '<span class="LC_nobreak"><label>';
1.108 raeburn 1773: if ($status eq 'new') {
1.170 raeburn 1774: my $checkstate;
1.254 raeburn 1775: if ($scope eq 'domains' || $scope eq 'users' || $scope eq 'course' || $scope eq 'ip') {
1.170 raeburn 1776: $checkstate = 'checked="checked"';
1777: }
1778: $output .= '<input type="checkbox" name="activate" value="'.$num.'" '.
1779: $checkstate.' />'.
1.108 raeburn 1780: &mt('Activate');
1781: } else {
1782: $output .= '<input type="checkbox" name="delete" value="'.$num.
1.200 bisitz 1783: '" />'.&mt('Delete').'</label></span><br /><span class="LC_nobreak">'.
1.108 raeburn 1784: '<label><input type="checkbox" name="update" value="'.
1785: $num.'" />'.&mt('Update');
1786: }
1.254 raeburn 1787: $output .= '</label></span><input type="hidden" name="scope_'.$num.'" value="'.$scope.'" />';
1.108 raeburn 1788: return $output;
1789: }
1790:
1791: sub dateboxes {
1792: my ($num,$start,$end) = @_;
1793: my $noend;
1794: if ($end == 0) {
1795: $noend = 'checked="checked"';
1796: }
1797: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1798: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1799: undef,undef,1);
1800: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1801: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1.200 bisitz 1802: undef,undef,1). ' <span class="LC_nobreak"><label>'.
1.108 raeburn 1803: '<input type="checkbox" name="noend_'.
1804: $num.'" '.$noend.' />'.&mt('No end date').
1.112 albertel 1805: '</label></span>';
1.108 raeburn 1806:
1807: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1808: return $output;
1809: }
1810:
1811: sub unpack_acc_key {
1812: my ($acc_key) = @_;
1813: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1814: return ($num,$scope,$end,$start);
1815: }
1816:
1817: sub set_identifiers {
1818: my ($status,$item,$now,$then,$scope) = @_;
1819: if ($status eq 'old') {
1820: return(&unpack_acc_key($item));
1821: } else {
1822: return($item,$scope,$then,$now);
1823: }
1824: }
1825:
1826: sub role_selectors {
1.172 raeburn 1827: my ($num,$role_id,$type,$content,$caller) = @_;
1.108 raeburn 1828: my ($output,$cdom,$cnum,$longid);
1829: if ($caller eq 'display') {
1830: $longid = '_'.$num.'_'.$role_id;
1.172 raeburn 1831: $cdom = $$content{'domain'};
1832: $cnum = $$content{'number'};
1.108 raeburn 1833: } elsif ($caller eq 'rolepicker') {
1834: $cdom = $env{'form.cdom'};
1835: $cnum = $env{'form.cnum'};
1836: }
1.221 raeburn 1837: my $crstype = 'Course';
1838: if ($cnum =~ /^$match_community$/) {
1839: $crstype = 'Community'
1840: }
1.108 raeburn 1841: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1.221 raeburn 1842: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$crstype);
1.108 raeburn 1843: if (!@{$sections}) {
1844: @{$sections} = ('none');
1845: } else {
1846: unshift(@{$sections},('all','none'));
1847: }
1848: if (!@{$groups}) {
1849: @{$groups} = ('none');
1850: } else {
1851: unshift(@{$groups},('all','none'));
1852: }
1853: my @allacesses = sort(keys(%{$accesshash}));
1854: my (%sectionhash,%grouphash);
1855: foreach my $sec (@{$sections}) {
1856: $sectionhash{$sec} = $sec;
1857: }
1858: foreach my $grp (@{$groups}) {
1859: $grouphash{$grp} = $grp;
1860: }
1861: my %lookup = (
1862: 'role' => $rolehash,
1863: 'access' => $accesshash,
1864: 'section' => \%sectionhash,
1865: 'group' => \%grouphash,
1866: );
1867: my @allaccesses = sort(keys(%{$accesshash}));
1868: my %allitems = (
1869: 'role' => $allroles,
1870: 'access' => \@allaccesses,
1871: 'section' => $sections,
1.172 raeburn 1872: 'group' => $groups,
1.108 raeburn 1873: );
1874: foreach my $item ('role','access','section','group') {
1.207 bisitz 1875: $output .= '<td><select name="'.$item.$longid.'" multiple="multiple" size="4">'."\n";
1.108 raeburn 1876: foreach my $entry (@{$allitems{$item}}) {
1877: if ($caller eq 'display') {
1878: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1879: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1.214 bisitz 1880: $output .= ' <option value="'.$entry.'" selected="selected">'.
1.108 raeburn 1881: $lookup{$item}{$entry}.'</option>';
1882: next;
1883: }
1884: }
1885: $output .= ' <option value="'.$entry.'">'.
1886: $lookup{$item}{$entry}.'</option>';
1887: }
1888: $output .= '</select>';
1889: }
1890: $output .= '</td>';
1891: return $output;
1892: }
1893:
1894: sub role_options_window {
1895: my ($r) = @_;
1896: my $type = $env{'form.type'};
1.172 raeburn 1897: my $rolenum = $env{'form.setroles'};
1898: my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/);
1899: my $role_elements;
1900: foreach my $item ('role','access','section','group') {
1901: $role_elements .= "'".$item.'_'.$rolenum."',";
1902: }
1903: $role_elements =~ s/,$//;
1904: my $role_selects = &role_selectors($num,$role_id,$type,undef,
1905: 'rolepicker');
1.108 raeburn 1906: $r->print(<<"END_SCRIPT");
1907: <script type="text/javascript">
1908: function setRoles() {
1.172 raeburn 1909: var role_elements = new Array($role_elements);
1910: for (var i=0; i<role_elements.length; i++) {
1.108 raeburn 1911: var copylist = '';
1912: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1913: if (document.rolepicker.elements[i].options[j].selected) {
1914: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1915: }
1916: }
1917: copylist = copylist.substr(0,copylist.length-1);
1.172 raeburn 1918: var openerItem = getIndexByName(role_elements[i]);
1919: opener.document.portform.elements[openerItem].value = copylist;
1.108 raeburn 1920: }
1.172 raeburn 1921: var roleAdder = getIndexByName('add_role_$num');
1922: opener.document.portform.elements[roleAdder].value = '$role_id';
1.108 raeburn 1923: self.close();
1924: }
1.172 raeburn 1925:
1926: function getIndexByName(item) {
1927: for (var i=0;i<opener.document.portform.elements.length;i++) {
1928: if (opener.document.portform.elements[i].name == item) {
1929: return i;
1930: }
1931: }
1932: return -1;
1933: }
1934:
1.108 raeburn 1935: </script>
1936: END_SCRIPT
1.220 bisitz 1937: $r->print(
1938: '<p>'
1939: .&mt('Select roles, '.lc($type).' status, section(s) and group(s) for users'
1940: .' who will be able to access the portfolio file.')
1941: .'</p>'
1942: );
1943: $r->print(
1944: '<form name="rolepicker" action="/adm/portfolio" method="post">'
1945: .'<table><tr>'
1946: .'<th>'.&mt('Roles').'</th>'
1947: .'<th>'.&mt("$type status").'</th>'
1948: .'<th>'.&mt('Sections').'</th>'
1949: .'<th>'.&mt('Groups').'</th>'
1950: .'</tr><tr>'.$role_selects.'</tr>'
1951: .'</table><br />'
1952: .'<input type="button" name="rolepickbutton" value="'.&mt('Save').'" onclick="setRoles()" />'
1953: );
1.108 raeburn 1954: return;
1.104 raeburn 1955: }
1956:
1.47 banghart 1957: sub select_files {
1.229 raeburn 1958: my ($r,$dir_list) = @_;
1.82 albertel 1959: if ($env{'form.continue'} eq 'true') {
1.60 banghart 1960: # here we update the selections for the currentpath
1961: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 1962: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1963: if (scalar(@items)){
1.229 raeburn 1964: my @ok_items;
1965: if (ref($dir_list) eq 'ARRAY') {
1966: foreach my $dir_line (@{$dir_list}) {
1967: my ($filename,undef,undef,undef,undef,undef,undef,undef,$size)=split(/\&/,$dir_line,10);
1968: if (grep(/^\Q$filename\E$/,@items)) {
1969: if ($size) {
1970: push(@ok_items,$filename);
1971: }
1972: }
1973: }
1974: }
1975: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @ok_items);
1.83 banghart 1976: }
1.62 banghart 1977: } else {
1978: #empty the file for a fresh start
1.83 banghart 1979: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 1980: }
1.82 albertel 1981: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 1982: my $java_files = join ",", @files;
1983: if ($java_files) {
1984: $java_files.=',';
1.60 banghart 1985: }
1.63 banghart 1986: my $javascript =(<<ENDSMP);
1.113 albertel 1987: <script type="text/javascript">
1.48 banghart 1988: function finishSelect() {
1.62 banghart 1989: ENDSMP
1.63 banghart 1990: $javascript .= 'fileList = "'.$java_files.'";';
1991: $javascript .= (<<ENDSMP);
1.49 banghart 1992: for (i=0;i<document.forms.checkselect.length;i++) {
1993: if (document.forms.checkselect[i].checked){
1.54 banghart 1994: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 1995: }
1996: }
1.186 albertel 1997: var hwfield = opener.document.getElementsByName('$env{'form.fieldname'}');
1998: hwfield[0].value = fileList;
1.48 banghart 1999: self.close();
2000: }
2001: </script>
2002: ENDSMP
1.63 banghart 2003: $r->print($javascript);
1.198 bisitz 2004: $r->print("<h1>".&mt('Select portfolio files')."</h1>");
1.88 albertel 2005: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
2006: if (@otherfiles) {
1.198 bisitz 2007: $r->print(&Apache::loncommon::start_data_table()
2008: .&Apache::loncommon::start_data_table_header_row()
2009: .'<th>'.&mt('Files selected from other directories:')."</th>"
2010: .&Apache::loncommon::end_data_table_header_row()
2011: );
1.88 albertel 2012: foreach my $file (@otherfiles) {
1.198 bisitz 2013: $r->print(&Apache::loncommon::start_data_table_row()
2014: .'<td>'.$file."</td>"
2015: .&Apache::loncommon::end_data_table_row()
2016: );
1.88 albertel 2017: }
1.198 bisitz 2018: $r->print(&Apache::loncommon::end_data_table()
2019: .'<br />'
2020: );
1.60 banghart 2021: }
1.198 bisitz 2022: $r->print('<div>'
2023: .&mt('Check as many files as you wish in response to the problem:')
2024: .'</div>'
2025: );
1.47 banghart 2026: }
1.138 albertel 2027:
1.176 albertel 2028: sub upload {
2029: my ($r,$url,$group)=@_;
1.226 raeburn 2030: my $formname = 'uploaddoc';
2031: my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formname.'.filename'});
2032: my ($state,$msg);
2033: if ($fname eq '') {
1.241 bisitz 2034: $r->print(
2035: &Apache::loncommon::confirmwrapper(
2036: &Apache::lonhtmlcommon::confirm_success(
2037: &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
1.226 raeburn 2038: 'so after eliminating special characters there was nothing left.',
1.241 bisitz 2039: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>'),1)));
2040:
2041: $r->print(&done(undef,$url));
1.226 raeburn 2042: return;
2043: }
1.195 raeburn 2044: my $disk_quota = &get_quota($group);
2045: my $portfolio_root = &get_portfolio_root();
2046: my $port_path = &get_port_path();
2047: my ($uname,$udom) = &get_name_dom($group);
2048: my $getpropath = 1;
2049: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
1.226 raeburn 2050: ($state,$msg) =
1.195 raeburn 2051: &Apache::loncommon::check_for_upload($env{'form.currentpath'},$fname,
1.226 raeburn 2052: $group,$formname,$portfolio_root,
1.195 raeburn 2053: $port_path,$disk_quota,
2054: $current_disk_usage,$uname,$udom);
1.176 albertel 2055: if ($state eq 'will_exceed_quota'
1.227 raeburn 2056: || $state eq 'file_locked'
2057: || $state eq 'zero_bytes') {
1.241 bisitz 2058: $r->print($msg.&done(undef,$url));
1.176 albertel 2059: return;
2060: }
2061:
1.231 raeburn 2062: my (%allfiles,%codebase,$mode,$mimetype);
1.226 raeburn 2063: if ($env{'form.'.$formname.'.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
1.193 raeburn 2064: if ($env{'form.parserflag'}) {
2065: $mode = 'parse';
2066: }
1.176 albertel 2067: }
1.226 raeburn 2068: my $context;
2069: if ($state eq 'existingfile') {
2070: $context = $state;
2071: }
1.231 raeburn 2072: my $subdir = $port_path.$env{'form.currentpath'};
2073: $subdir =~ s{(/)$}{};
1.226 raeburn 2074: my ($result,$timestamp) =
1.231 raeburn 2075: &Apache::lonnet::userfileupload($formname,$context,$subdir,
2076: $mode,\%allfiles,\%codebase,undef,undef,
2077: undef,undef,undef,undef,\$mimetype);
1.226 raeburn 2078: if ($state eq 'existingfile') {
2079: my $group_elem;
2080: my $rootdir = $r->dir_config('lonDaemons').'/tmp/overwrites';
2081: if ($group eq '') {
2082: $rootdir .= '/'.$env{'user.domain'}.'/'.$env{'user.name'};
2083: } else {
2084: $rootdir .= '/'.$env{'course.'.$env{'request.course.id'}.'.domain'}.
2085: '/'.$env{'course.'.$env{'request.course.id'}.'.num'};
2086: $group_elem = '<input type="hidden" name="group" value="'.$group.'" />';
2087: }
2088: if (($result eq $rootdir.'/'.$port_path.$env{'form.currentpath'}.$fname) && ($timestamp =~ /^\d+$/)) {
2089: my $showfname = &HTML::Entities::encode($fname,'&<>"');
2090: my %lt = &Apache::lonlocal::texthash (
2091: over => 'Overwrite existing file?',
2092: yes => 'Yes',
2093: no => 'No',
2094: undo => 'This action can not be undone.',
2095: conf => 'Are you sure you want to overwrite an existing file?',
2096: cont => 'Continue',
2097: );
1.230 raeburn 2098: my $parserflag;
2099: my $hidden = &hidden_elems();
2100: if ($mode eq 'parse') {
2101: $parserflag = '<input type="hidden" name="parserflag" value="1" />';
2102: }
1.226 raeburn 2103: $r->print(<<"END");
2104: <script type="text/javascript">
2105: // <![CDATA[
2106: function confirmOverwrite() {
1.230 raeburn 2107: var chosen;
2108: if (document.existingfile.overwrite.length) {
2109: for (var i=0; i<document.existingfile.overwrite.length; i++) {
2110: if (document.existingfile.overwrite[i].checked) {
2111: chosen = document.existingfile.overwrite[i].value;
2112: }
2113: }
2114: }
2115: if (chosen == 1) {
2116: if (confirm('$lt{'conf'}')) {
2117: document.existingfile.action.value = "process_overwrite";
2118: return true;
2119: } else {
2120: document.existingfile.action.value = "cancel_overwrite";
2121: if (document.existingfile.overwrite.length) {
2122: for (var i=0; i<document.existingfile.overwrite.length; i++) {
2123: if (document.existingfile.overwrite[i].value == "0") {
2124: document.existingfile.overwrite[i].checked = true;
2125: }
1.226 raeburn 2126: }
2127: }
1.230 raeburn 2128: return false;
1.226 raeburn 2129: }
1.230 raeburn 2130: } else {
1.226 raeburn 2131: document.existingfile.action.value = "cancel_overwrite";
1.230 raeburn 2132: return true;
1.226 raeburn 2133: }
2134: }
2135: // ]]>
2136: </script>
1.245 bisitz 2137: <p>
1.226 raeburn 2138: $msg
1.245 bisitz 2139: </p>
2140: <form method="post" action="$url" name="existingfile" onsubmit="return confirmOverwrite();">
2141: <p class="LC_nobreak">$lt{'over'}
1.230 raeburn 2142: <label><input type="radio" name="overwrite" value="1" />
1.226 raeburn 2143: $lt{'yes'}</label>
1.245 bisitz 2144: <label><input type="radio" name="overwrite" value="0" checked="checked" />$lt{'no'}</label></p>
2145: <p>
1.226 raeburn 2146: <input type="hidden" name="action" value="cancel_overwrite" />
2147: <input type="hidden" name="filename" value="$showfname" />
2148: <input type="hidden" name="timestamp" value="$timestamp" />
1.230 raeburn 2149: $hidden
2150: $parserflag
1.226 raeburn 2151: $group_elem
2152: <input type="submit" name="process" value="$lt{'cont'}" />
1.245 bisitz 2153: </p>
2154: </form>
1.226 raeburn 2155: END
2156: } else {
1.241 bisitz 2157: $r->print(
2158: &Apache::loncommon::confirmwrapper(
2159: &Apache::lonhtmlcommon::confirm_success(
2160: &mt('An error occurred ([_1]) while trying to upload [_2].'
2161: ,$result,&display_file(undef,$fname)),1)));
2162: $r->print(&done(undef,$url));
1.226 raeburn 2163: }
2164: } elsif ($result !~ m|^/uploaded/|) {
1.241 bisitz 2165: $r->print(
2166: &Apache::loncommon::confirmwrapper(
2167: &Apache::lonhtmlcommon::confirm_success(
2168: &mt('An error occurred ([_1]) while trying to upload [_2].'
2169: ,$result,&display_file(undef,$fname)),1)));
2170: $r->print(&done(undef,$url));
1.176 albertel 2171: } else {
1.231 raeburn 2172: if (!&suppress_embed_prompt()) {
2173: if ($mimetype eq 'text/html') {
2174: if (keys(%allfiles) > 0) {
2175: &print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
2176: return;
2177: } else {
1.241 bisitz 2178: $r->print('<p class="LC_warning">'.&mt('No embedded items identified.').'</p>');
1.231 raeburn 2179: }
1.226 raeburn 2180: }
1.231 raeburn 2181: }
1.241 bisitz 2182: $r->print(
2183: &Apache::loncommon::confirmwrapper(
2184: &Apache::lonhtmlcommon::confirm_success(
2185: &mt('File successfully uploaded'))));
1.231 raeburn 2186: $r->print(&done(undef,$url));
1.226 raeburn 2187: }
1.231 raeburn 2188: return;
1.226 raeburn 2189: }
2190:
1.230 raeburn 2191: sub hidden_elems {
2192: my $contelem;
2193: if ($env{'form.mode'} eq 'selectfile') {
2194: $contelem = '<input type="hidden" name="continue" value="true" />';
2195: }
2196: return <<END;
2197: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
1.235 raeburn 2198: <input type="hidden" name="symb" value="$env{'form.symb'}" />
1.230 raeburn 2199: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
2200: <input type="hidden" name="mode" value="$env{'form.mode'}" />
2201: <input type="hidden" name="showversions" value="$env{'form.showversions'}" />
2202: $contelem
2203: END
2204: }
2205:
1.226 raeburn 2206: sub print_dependency_form {
1.231 raeburn 2207: my ($r,$url,$allfiles,$codebase,$result) = @_;
2208: my $container = &HTML::Entities::encode($result,'<>"&');
2209: my $state = &embedded_form_elems($container);
2210: my ($embedded,$num,$pathchg) = &Apache::loncommon::ask_for_embedded_content($url,$state,$allfiles,$codebase,
1.226 raeburn 2211: {'error_on_invalid_names' => 1,
2212: 'ignore_remote_references' => 1,});
2213: if ($embedded) {
1.231 raeburn 2214: if ($num || $pathchg) {
2215: $r->print('<h3>'.&mt("Reference Warning").'</h3>');
2216: } else {
2217: $r->print('<h3>'.&mt("Reference Information").'</h3>');
2218: }
2219: if ($num) {
1.238 raeburn 2220: $r->print('<p>'.&mt('Completed upload of the file.').' '.
2221: &mt('This file contained references to other files.').' '.
2222: &mt('You must upload the referenced files or else the uploaded file may not work properly.').
2223: '</p>'.
1.231 raeburn 2224: '<p>'.&mt("Please select the locations from which the referenced files are to be uploaded.").'</p>'.
2225: $embedded.
2226: '<p>'.&mt('or').'</p>'.&done('Return to directory',$url));
2227: } else {
2228: $r->print('<p>'.&mt("Completed upload of the file. This file contained references to other files.").'</p>'.
2229: $embedded.
2230: '<p>'.&done('Return to directory',$url).'</p>');
2231: }
1.226 raeburn 2232: } else {
2233: $r->print(&done(undef,$url));
2234: }
2235: return;
2236: }
2237:
2238: sub overwrite {
2239: my ($r,$url,$group)=@_;
2240: my $formname = 'existingfile';
2241: my $port_path = &get_port_path();
2242: my $fname = &Apache::lonnet::clean_filename($env{'form.filename'});
1.231 raeburn 2243: my (%allfiles,%codebase,$mode,$mimetype);
1.230 raeburn 2244: unless (&suppress_embed_prompt()) {
2245: if ($env{'form.parserflag'}) {
2246: if ($fname =~ /\.s?html?$/i) {
2247: $mode = 'parse';
2248: }
1.226 raeburn 2249: }
2250: }
2251: if ($fname eq '') {
1.245 bisitz 2252: $r->print(
2253: &Apache::loncommon::confirmwrapper(
2254: &Apache::lonhtmlcommon::confirm_success(
2255: &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
1.226 raeburn 2256: 'so after eliminating special characters there was nothing left.',
1.245 bisitz 2257: '<span class="LC_filename">'.$env{'form.filename'}.'</span>'),1)));
2258: $r->print(&done(undef,$url));
1.226 raeburn 2259: return;
2260: }
2261: $env{'form.'.$formname.'.filename'} = $fname;
1.231 raeburn 2262: my $subdir = $port_path.$env{'form.currentpath'};
2263: $subdir =~ s{(/)$}{};
1.226 raeburn 2264: my $result=
1.231 raeburn 2265: &Apache::lonnet::userfileupload($formname,'overwrite',$subdir,$mode,
2266: \%allfiles,\%codebase,undef,undef,undef,
2267: undef,undef,undef,\$mimetype);
1.226 raeburn 2268: if ($result !~ m|^/uploaded/|) {
1.245 bisitz 2269: $r->print(
2270: &Apache::loncommon::confirmwrapper(
2271: &Apache::lonhtmlcommon::confirm_success(
2272: &mt('An error occurred ([_1]) while trying to overwrite [_2].'
2273: ,$result,&display_file(undef,$fname)),1)));
1.226 raeburn 2274: } else {
1.231 raeburn 2275: if ($mode eq 'parse') {
2276: if ($mimetype eq 'text/html') {
2277: if (keys(%allfiles) > 0) {
2278: &print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
2279: return;
2280: } else {
1.245 bisitz 2281: $r->print(
2282: &Apache::loncommon::confirmwrapper(
2283: &Apache::lonhtmlcommon::confirm_success(
2284: &mt('Overwriting completed.'))
2285: .'<br />'.&mt('No embedded items identified.')));
1.231 raeburn 2286: }
1.195 raeburn 2287: }
1.245 bisitz 2288: } else {
2289: $r->print(
2290: &Apache::loncommon::confirmwrapper(
2291: &Apache::lonhtmlcommon::confirm_success(
2292: &mt('Overwriting completed.'))));
1.226 raeburn 2293: }
1.176 albertel 2294: }
2295:
1.230 raeburn 2296: my $group_elem;
2297: if (defined($env{'form.group'})) {
2298: $group_elem = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
2299: if (defined($env{'form.ref'})) {
2300: $group_elem .= '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'."\n";
2301: }
2302: }
2303: my $hidden = &hidden_elems();
1.245 bisitz 2304: $r->print(
2305: &Apache::lonhtmlcommon::actionbox(
2306: ['<a href="javascript:document.overwritedone.submit();">'
2307: .&mt('Return to directory')
2308: .'</a>'])
2309: .'<form name="overwritedone" method="post" action="'.$url.'">'
2310: .$hidden
2311: .$group_elem
2312: .'</form>'
2313: );
2314: return;
1.230 raeburn 2315: }
2316:
1.80 banghart 2317: sub lock_info {
1.137 albertel 2318: my ($r,$url,$group) = @_;
1.191 raeburn 2319: my ($uname,$udom) = &get_name_dom($group);
1.102 raeburn 2320: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
2321: $uname);
1.84 banghart 2322: my $file_name = $env{'form.lockinfo'};
1.138 albertel 2323: $file_name = &prepend_group($file_name);
1.102 raeburn 2324: if (defined($file_name) && defined($$current_permissions{$file_name})) {
2325: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1.156 albertel 2326: next if (ref($array_item) ne 'ARRAY');
2327:
2328: my $filetext;
2329: if (defined($group)) {
2330: $filetext = '<strong>'.$env{'form.lockinfo'}.
2331: '</strong> (group: '.$group.')';
2332: } else {
1.241 bisitz 2333: $filetext = '<span class="LC_filename">'.$file_name.'</span>';
1.156 albertel 2334: }
2335:
2336: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
2337: '</strong><br />';
2338: if ($$array_item[-1] eq 'graded') {
2339: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
2340: $filetext,$title));
2341: } elsif ($$array_item[-1] eq 'handback') {
2342: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
2343: $filetext,$title));
2344: } else {
2345: # submission style lock
2346: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
2347: $filetext,$title));
2348: }
2349: my %course_description =
2350: &Apache::lonnet::coursedescription($$array_item[1]);
2351: if ( $course_description{'description'} ne '') {
1.188 bisitz 2352: $r->print(&mt('In the course:').' <strong>'.$course_description{'description'}.'</strong><br />');
1.156 albertel 2353: }
1.102 raeburn 2354: }
1.84 banghart 2355: }
1.241 bisitz 2356: $r->print(&done(undef,$url));
1.80 banghart 2357: return 'ok';
2358: }
1.138 albertel 2359:
1.25 albertel 2360: sub createdir {
1.191 raeburn 2361: my ($r,$url,$group)=@_;
1.82 albertel 2362: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.241 bisitz 2363: # Display warning in case of directory name cleaning has changed the directory name
2364: if ($newdir ne $env{'form.newdir'}) {
2365: $r->print(
2366: '<p><span class="LC_warning">'
2367: .&mt('Invalid characters')
2368: .'</span><br />'
2369: .&mt('The new directory name was changed from [_1] to [_2].'
2370: ,'<span class="LC_filename">'.$env{'form.newdir'}.'</span>'
2371: ,'<span class="LC_filename">'.$newdir.'</span>')
2372: .'</p>'
2373: );
2374: }
2375:
2376: # Directory name empty?
1.28 albertel 2377: if ($newdir eq '') {
1.241 bisitz 2378: $r->print(
2379: &Apache::loncommon::confirmwrapper(
2380: &Apache::lonhtmlcommon::confirm_success(
2381: &mt('Error: no directory name was provided.'),1)));
2382: $r->print(&done(undef,$url));
2383: return;
1.94 raeburn 2384: }
1.241 bisitz 2385:
1.138 albertel 2386: my $portfolio_root = &get_portfolio_root();
1.233 raeburn 2387: my ($dirlistref,$listerror) = &get_dir_list($portfolio_root,undef,$group);
1.37 banghart 2388: my $found_file = 0;
1.233 raeburn 2389: if (ref($dirlistref) eq 'ARRAY') {
2390: foreach my $line (@{$dirlistref}) {
2391: my ($filename)=split(/\&/,$line,2);
2392: if ($filename eq $newdir){
2393: $found_file = 1;
2394: }
1.37 banghart 2395: }
2396: }
1.241 bisitz 2397: if ($found_file) {
2398: $r->print(
2399: &Apache::loncommon::confirmwrapper(
2400: &Apache::lonhtmlcommon::confirm_success(
2401: &mt('Unable to create a directory named [_1].'
2402: ,'<span class="LC_filename">'.$newdir.'</span>'),1)
2403: .'<br />'.&mt('A file or directory by that name already exists.')));
1.37 banghart 2404: } else {
1.191 raeburn 2405: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 2406: my $port_path = &get_port_path();
1.94 raeburn 2407: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
2408: $port_path.$env{'form.currentpath'}.$newdir);
1.37 banghart 2409: if ($result ne 'ok') {
1.241 bisitz 2410: $r->print(
2411: &Apache::loncommon::confirmwrapper(
2412: &Apache::lonhtmlcommon::confirm_success(
2413: &mt('An error occurred ([_1]) while trying to create a new directory [_2].'
2414: ,$result,&display_file()),1)));
2415:
2416: } else {
2417: $r->print(
2418: &Apache::loncommon::confirmwrapper(
2419: &Apache::lonhtmlcommon::confirm_success(
2420: &mt('Directory successfully created'))));
1.37 banghart 2421: }
1.24 albertel 2422: }
1.137 albertel 2423: $r->print(&done(undef,$url));
1.94 raeburn 2424: }
2425:
2426: sub get_portfolio_root {
1.163 raeburn 2427: my ($udom,$uname,$group) = @_;
1.160 raeburn 2428: if (!(defined($udom)) || !(defined($uname))) {
1.191 raeburn 2429: ($uname,$udom) = &get_name_dom($group);
1.160 raeburn 2430: }
1.163 raeburn 2431: my $path = '/userfiles/portfolio';
2432: if (!defined($group)) {
2433: if (defined($env{'form.group'})) {
2434: $group = $env{'form.group'};
2435: }
1.94 raeburn 2436: }
1.163 raeburn 2437: if (defined($group)) {
2438: $path = '/userfiles/groups/'.$group.'/portfolio';
2439: }
1.191 raeburn 2440: return $path;
1.94 raeburn 2441: }
2442:
1.126 raeburn 2443: sub get_group_quota {
2444: my ($group) = @_;
2445: my $group_quota;
2446: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2447: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2448: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2449: if (%curr_groups) {
2450: my %group_info = &Apache::longroup::get_group_settings(
2451: $curr_groups{$group});
1.251 raeburn 2452: $group_quota = $group_info{'quota'}; #expressed in MB
1.126 raeburn 2453: if ($group_quota) {
2454: $group_quota = 1000 * $group_quota; #expressed in k
1.191 raeburn 2455: }
1.126 raeburn 2456: }
2457: return $group_quota;
1.191 raeburn 2458: }
1.126 raeburn 2459:
1.94 raeburn 2460: sub get_dir_list {
1.191 raeburn 2461: my ($portfolio_root,$path,$group) = @_;
1.176 albertel 2462: $path ||= $env{'form.currentpath'};
1.191 raeburn 2463: my ($uname,$udom) = &get_name_dom($group);
2464: my $getpropath = 1;
2465: return &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.94 raeburn 2466: }
2467:
2468: sub get_name_dom {
1.191 raeburn 2469: my ($group) = @_;
1.94 raeburn 2470: my ($uname,$udom);
1.191 raeburn 2471: if (defined($group)) {
1.94 raeburn 2472: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2473: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
2474: } else {
2475: $udom = $env{'user.domain'};
2476: $uname = $env{'user.name'};
2477: }
2478: return ($uname,$udom);
2479: }
2480:
1.102 raeburn 2481: sub prepend_group {
1.138 albertel 2482: my ($filename) = @_;
2483: if (defined($env{'form.group'})) {
2484: $filename = $env{'form.group'}.$filename;
1.102 raeburn 2485: }
2486: return $filename;
2487: }
2488:
1.94 raeburn 2489: sub get_namespace {
2490: my $namespace = 'portfolio';
1.138 albertel 2491: if (defined($env{'form.group'})) {
1.191 raeburn 2492: my ($uname,$udom) = &get_name_dom($env{'form.group'});
1.138 albertel 2493: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
1.94 raeburn 2494: }
2495: return $namespace;
2496: }
2497:
2498: sub get_port_path {
2499: my $port_path;
1.138 albertel 2500: if (defined($env{'form.group'})) {
2501: $port_path = "groups/$env{'form.group'}/portfolio";
1.94 raeburn 2502: } else {
2503: $port_path = 'portfolio';
2504: }
2505: return $port_path;
1.24 albertel 2506: }
2507:
1.120 raeburn 2508: sub missing_priv {
1.138 albertel 2509: my ($r,$url,$priv) = @_;
1.239 raeburn 2510: my %longtext =
2511: &Apache::lonlocal::texthash(
1.120 raeburn 2512: upload => 'upload files',
2513: delete => 'delete files',
2514: rename => 'rename files',
2515: setacl => 'set access controls for files',
1.239 raeburn 2516: );
1.120 raeburn 2517: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
2518: my $rtnlink = '<a href="'.$url;
2519: if ($url =~ /\?/) {
2520: $rtnlink .= '&';
2521: } else {
2522: $rtnlink .= '?';
2523: }
2524: $rtnlink .= 'currentpath='.$escpath;
1.188 bisitz 2525: $r->print('<h3>'.&mt('Action disallowed').'</h3>');
1.239 raeburn 2526: $r->print(&mt('You do not have sufficient privileges to [_1]',
2527: $longtext{$priv}));
1.138 albertel 2528: if (defined($env{'form.group'})) {
1.239 raeburn 2529: $r->print(' '.&mt("in the group's group portfolio."));
1.137 albertel 2530: $rtnlink .= &group_args()
1.120 raeburn 2531: } else {
1.239 raeburn 2532: $r->print(' '.&mt('in this portfolio.'));
1.120 raeburn 2533: }
1.188 bisitz 2534: $rtnlink .= '">'.&mt('Return to directory').'</a>';
1.120 raeburn 2535: $r->print('<br />'.$rtnlink);
2536: return;
2537: }
2538:
1.132 raeburn 2539: sub coursegrp_portfolio_header {
1.137 albertel 2540: my ($cdom,$cnum,$grp_desc)=@_;
1.132 raeburn 2541: my $gpterm = &Apache::loncommon::group_term();
2542: my $ucgpterm = $gpterm;
2543: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.137 albertel 2544: if ($env{'form.ref'}) {
1.136 raeburn 2545: &Apache::lonhtmlcommon::add_breadcrumb
2546: ({href=>"/adm/coursegroups",
2547: text=>"Groups",
2548: title=>"Course Groups"});
2549: }
1.132 raeburn 2550: &Apache::lonhtmlcommon::add_breadcrumb
1.138 albertel 2551: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
1.132 raeburn 2552: text=>"$ucgpterm: $grp_desc",
2553: title=>"Go to group's home page"},
1.137 albertel 2554: {href=>"/adm/coursegrp_portfolio?".&group_args(),
1.132 raeburn 2555: text=>"Group Portfolio",
1.136 raeburn 2556: title=>"Display group portfolio"});
1.132 raeburn 2557: my $output = &Apache::lonhtmlcommon::breadcrumbs(
2558: &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
2559: return $output;
2560: }
2561:
1.174 raeburn 2562: sub get_quota {
2563: my ($group) = @_;
2564: my $disk_quota;
2565: if (defined($group)) {
2566: my $grp_quota = &get_group_quota($group); # quota expressed in k
2567: if ($grp_quota ne '') {
2568: $disk_quota = $grp_quota;
2569: } else {
2570: $disk_quota = 0;
2571: }
2572: } else {
2573: $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
1.251 raeburn 2574: $env{'user.domain'}); #expressed in MB
1.257 raeburn 2575: $disk_quota = 1024 * $disk_quota; # convert from MB to kB
1.174 raeburn 2576: }
2577: return $disk_quota;
2578: }
2579:
1.195 raeburn 2580: sub suppress_embed_prompt {
2581: my $suppress_prompt = 0;
2582: if (($env{'request.role'} =~ /^st/) && ($env{'request.course.id'} ne '')) {
2583: if ($env{'course.'.$env{'request.course.id'}.'.suppress_embed_prompt'} eq 'yes') {
2584: $suppress_prompt = 1;
2585: }
2586: }
2587: return $suppress_prompt;
2588: }
2589:
1.231 raeburn 2590: sub embedded_form_elems {
2591: my ($container) = @_;
2592: my $state = <<STATE;
2593: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
1.235 raeburn 2594: <input type="hidden" name="symb" value="$env{'form.symb'}" />
1.231 raeburn 2595: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
2596: <input type="hidden" name="mode" value="$env{'form.mode'}" />
2597: <input type="hidden" name="container" value="$container" />
2598: STATE
2599: if ($env{'form.group'} ne '') {
2600: $state .= '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />'."\n";
2601: }
2602: return $state;
2603: }
1.195 raeburn 2604:
1.256 musolffc 2605: # Find space available in a user's portfolio (convert to bytes)
2606: sub free_space {
2607: my ($group) = @_;
2608: my $disk_quota = &get_quota($group); # Expressed in kB
2609: my ($uname,$udom) = &get_name_dom($group);
2610: my $portfolio_root = &get_portfolio_root();
2611: my $getpropath = 1;
2612: my $current_disk_usage = &Apache::lonnet::diskusage($udom, $uname,
2613: $portfolio_root, $getpropath); # Expressed in kB
2614: my $free_space = 1024 * ($disk_quota - $current_disk_usage);
2615: return $free_space;
2616: }
2617:
1.24 albertel 2618: sub handler {
2619: # this handles file management
2620: my $r = shift;
1.73 banghart 2621: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.108 raeburn 2622: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
2623: 'fieldname','mode','rename','continue','group','access','setnum',
1.235 raeburn 2624: 'cnum','cdom','type','setroles','showversions','ref','symb']);
1.138 albertel 2625: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
1.94 raeburn 2626: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
2627: $url = $1.$2;
2628: $caller = $2;
2629: }
1.137 albertel 2630: my ($can_modify,$can_delete,$can_upload,$can_setacl);
1.94 raeburn 2631: if ($caller eq 'coursegrp_portfolio') {
2632: # Needs to be in a course
2633: if (! ($env{'request.course.fn'})) {
2634: # Not in a course
2635: $env{'user.error.msg'}=
2636: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
2637: return HTTP_NOT_ACCEPTABLE;
2638: }
2639: my $earlyout = 0;
1.136 raeburn 2640: my $view_permission =
2641: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.137 albertel 2642: $env{'form.group'} =~ s/\W//g;
1.138 albertel 2643: $group = $env{'form.group'};
1.191 raeburn 2644: if ($group ne '') {
2645: ($uname,$udom) = &get_name_dom($group);
1.99 raeburn 2646: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98 albertel 2647: $group);
2648: if (%curr_groups) {
1.132 raeburn 2649: my %grp_content = &Apache::longroup::get_group_settings(
2650: $curr_groups{$group});
2651: $grp_desc = &unescape($grp_content{'description'});
1.94 raeburn 2652: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
2653: $env{'request.course.id'}.'/'.$group))) {
1.138 albertel 2654: $portfolio_root = &get_portfolio_root();
1.94 raeburn 2655: } else {
1.185 banghart 2656: $r->print(&mt('You do not have the privileges required to access the shared files space for this group.'));
1.94 raeburn 2657: $earlyout = 1;
2658: }
2659: } else {
1.185 banghart 2660: $r->print(&mt('Not a valid group for this course'));
1.94 raeburn 2661: $earlyout = 1;
2662: }
1.212 weissno 2663: $title = &mt('Group portfolio for [_1]', $group);
1.94 raeburn 2664: } else {
1.185 banghart 2665: $r->print(&mt('Invalid group'));
1.94 raeburn 2666: $earlyout = 1;
2667: }
2668: if ($earlyout) { return OK; }
1.126 raeburn 2669: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
1.120 raeburn 2670: $can_modify = 1;
2671: $can_delete = 1;
1.126 raeburn 2672: $can_upload = 1;
2673: $can_setacl = 1;
2674: } else {
2675: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
2676: $can_setacl = 1;
2677: }
2678: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
2679: $can_upload = 1;
2680: }
2681: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
2682: $can_modify = 1;
2683: }
2684: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
2685: $can_delete = 1;
2686: }
1.120 raeburn 2687: }
1.94 raeburn 2688: } else {
2689: ($uname,$udom) = &get_name_dom();
2690: $portfolio_root = &get_portfolio_root();
1.250 bisitz 2691: $title = 'My Space';
1.120 raeburn 2692: $can_modify = 1;
2693: $can_delete = 1;
2694: $can_upload = 1;
2695: $can_setacl = 1;
1.94 raeburn 2696: }
2697:
1.138 albertel 2698: my $port_path = &get_port_path();
1.24 albertel 2699: &Apache::loncommon::no_cache($r);
2700: &Apache::loncommon::content_type($r,'text/html');
2701: $r->send_http_header;
2702: # Give the LON-CAPA page header
1.203 raeburn 2703: my $brcrum = [{href=>"/adm/portfolio",text=>"Portfolio Manager"}];
2704:
1.256 musolffc 2705: my $js = '<script type="text/javascript"
2706: src="/res/adm/includes/file_upload.js"></script>';
2707:
1.82 albertel 2708: if ($env{"form.mode"} eq 'selectfile'){
1.256 musolffc 2709: $r->print(&Apache::loncommon::start_page($title, $js,
1.97 albertel 2710: {'only_body' => 1}));
1.108 raeburn 2711: } elsif ($env{'form.action'} eq 'rolepicker') {
1.256 musolffc 2712: $r->print(&Apache::loncommon::start_page('New role-based condition', $js,
1.108 raeburn 2713: {'no_nav_bar' => 1, }));
1.205 raeburn 2714: } elsif ($caller eq 'coursegrp_portfolio') {
1.256 musolffc 2715: $r->print(&Apache::loncommon::start_page($title, $js));
1.74 banghart 2716: } else {
1.256 musolffc 2717: $r->print(&Apache::loncommon::start_page($title, $js,
1.203 raeburn 2718: {'bread_crumbs' => $brcrum}));
1.205 raeburn 2719: if (!&Apache::lonnet::usertools_access($uname,$udom,'portfolio')) {
2720: $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
2721: &mt('This is a result of one of the following:').'<ul>'.
2722: '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
2723: '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
2724: '</ul>');
2725: $r->print(&Apache::loncommon::end_page());
2726: return OK;
2727: }
1.74 banghart 2728: }
1.24 albertel 2729: $r->rflush();
1.235 raeburn 2730: # Check if access to portfolio is blocked by one or more blocking events in courses.
1.175 raeburn 2731: my ($blocked,$blocktext) =
2732: &Apache::loncommon::blocking_status('port',$uname,$udom);
2733: if ($blocked) {
1.235 raeburn 2734: my $evade_block;
2735: # If portfolio display is in a window popped up from a "Select Portfolio Files"
2736: # link in a .task resource, check if access to the task included proctor validation
2737: # of check-in to a slot limited by IP.
2738: # If so, and the slot is between its open and close dates, override the block.
2739: if ($env{'request.course.id'} && $env{'form.symb'}) {
2740: (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
2741: if ($res =~ /\.task$/i) {
2742: my %history =
2743: &Apache::lonnet::restore($env{'form.symb'},$env{'request.course.id'},
2744: $env{'user.domain'},$env{'user.name'});
2745: my $version = $history{'resource.0.version'};
2746: if ($history{'resource.'.$version.'.0.checkedin'}) {
2747: if ($history{'resource.'.$version.'.0.checkedin.slot'}) {
2748: my %slot = &Apache::lonnet::get_slot($history{'resource.'.$version.'.0.checkedin.slot'});
2749: if ($slot{'ip'}) {
2750: if (&Apache::loncommon::check_ip_acc($slot{'ip'})) {
2751: my $now = time;
2752: if (($slot{'slottime'} < $now) && ($slot{'endtime'} > $now)) {
2753: $evade_block = 1;
2754: }
2755: }
2756: }
2757: }
2758: }
2759: }
2760: }
2761: unless ($evade_block) {
2762: $r->print($blocktext);
2763: $r->print(&Apache::loncommon::end_page());
2764: return OK;
2765: }
1.175 raeburn 2766: }
1.226 raeburn 2767: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.241 bisitz 2768: $r->print(
2769: '<p><span class="LC_warning">'
2770: .&mt('No file was selected to upload.')
1.244 raeburn 2771: .'</span><br />'
1.241 bisitz 2772: .&mt('To upload a file, click [_1]Browse...[_2] and select a file, then click [_1]Upload[_2].'
2773: ,'<strong>','</strong>')
2774: .'</p>'
2775: );
1.226 raeburn 2776: }
1.82 albertel 2777: if ($env{'form.meta'}) {
1.94 raeburn 2778: &open_form($r,$url);
1.252 bisitz 2779: $r->print(&mt('Edit Metadata').'<br />');
1.137 albertel 2780: &close_form($r,$url);
1.70 banghart 2781: }
1.82 albertel 2782: if ($env{'form.uploaddoc.filename'}) {
1.120 raeburn 2783: if ($can_upload) {
1.137 albertel 2784: &upload($r,$url,$group);
1.120 raeburn 2785: } else {
1.138 albertel 2786: &missing_priv($r,$url,'upload');
1.120 raeburn 2787: }
1.226 raeburn 2788: } elsif ($env{'form.action'} eq 'process_overwrite') {
2789: if ($can_upload) {
2790: &overwrite($r,$url,$group);
2791: } else {
2792: &missing_priv($r,$url,'existingfile');
2793: }
1.176 albertel 2794: } elsif ($env{'form.action'} eq 'upload_embedded') {
2795: if ($can_upload) {
1.195 raeburn 2796: my $disk_quota = &get_quota($group);
2797: my $getpropath = 1;
2798: my $current_disk_usage =
2799: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
1.231 raeburn 2800: my $container = &HTML::Entities::encode($env{'form.container'},'<>&"');
2801: my $state = &embedded_form_elems($container).
2802: '<input type="hidden" name="action" value="modify_orightml" />';
2803: my ($result,$flag) =
1.195 raeburn 2804: &Apache::loncommon::upload_embedded('portfolio',$port_path,$uname,$udom,
1.231 raeburn 2805: $group,$portfolio_root,$group,$disk_quota,$current_disk_usage,$state,$url);
2806: $r->print($result.&done('Return to directory',$url));
2807: } else {
2808: &missing_priv($r,$url,'upload');
2809: }
2810: } elsif ($env{'form.action'} eq 'modify_orightml') {
2811: if ($can_upload) {
1.234 raeburn 2812: my $result =
1.242 raeburn 2813: &Apache::loncommon::modify_html_refs('portfolio',$port_path,$uname,
2814: $udom,$portfolio_root);
1.234 raeburn 2815: $r->print($result.
2816: &done('Return to directory',$url));
1.176 albertel 2817: } else {
2818: &missing_priv($r,$url,'upload');
2819: }
1.82 albertel 2820: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.120 raeburn 2821: if ($can_delete) {
1.164 raeburn 2822: &delete_confirmed($r,$url,$group);
1.120 raeburn 2823: } else {
1.138 albertel 2824: &missing_priv($r,$url,'delete');
1.120 raeburn 2825: }
1.82 albertel 2826: } elsif ($env{'form.action'} eq 'delete') {
1.120 raeburn 2827: if ($can_delete) {
1.191 raeburn 2828: &delete($r,$url,$group);
1.120 raeburn 2829: } else {
1.138 albertel 2830: &missing_priv($r,$url,'delete');
1.120 raeburn 2831: }
1.82 albertel 2832: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.120 raeburn 2833: if ($can_delete) {
1.191 raeburn 2834: &delete_dir_confirmed($r,$url,$group);
1.120 raeburn 2835: } else {
1.138 albertel 2836: &missing_priv($r,$url,'delete');
1.120 raeburn 2837: }
2838: } elsif ($env{'form.action'} eq 'deletedir') {
2839: if ($can_delete) {
1.137 albertel 2840: &delete_dir($r,$url);
1.120 raeburn 2841: } else {
1.138 albertel 2842: &missing_priv($r,$url,'delete');
1.120 raeburn 2843: }
1.82 albertel 2844: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.120 raeburn 2845: if ($can_modify) {
1.164 raeburn 2846: &rename_confirmed($r,$url,$group);
1.120 raeburn 2847: } else {
1.138 albertel 2848: &missing_priv($r,$url,'rename');
1.120 raeburn 2849: }
1.82 albertel 2850: } elsif ($env{'form.rename'}) {
2851: $env{'form.selectfile'} = $env{'form.rename'};
2852: $env{'form.action'} = 'rename';
1.120 raeburn 2853: if ($can_modify) {
1.191 raeburn 2854: &rename($r,$url,$group);
1.120 raeburn 2855: } else {
1.138 albertel 2856: &missing_priv($r,$url,'rename');
1.120 raeburn 2857: }
1.104 raeburn 2858: } elsif ($env{'form.access'}) {
2859: $env{'form.selectfile'} = $env{'form.access'};
1.170 raeburn 2860: if (!defined($env{'form.action'})) {
2861: $env{'form.action'} = 'chgaccess';
2862: }
2863: &display_access($r,$url,$group,$can_setacl,$port_path,$env{'form.action'});
2864: } elsif (($env{'form.action'} eq 'chgaccess') ||
2865: ($env{'form.action'} eq 'chgconditions')) {
1.120 raeburn 2866: if ($can_setacl) {
1.137 albertel 2867: &update_access($r,$url,$group,$port_path);
1.120 raeburn 2868: } else {
1.138 albertel 2869: &missing_priv($r,$url,'setacl');
1.120 raeburn 2870: }
1.108 raeburn 2871: } elsif ($env{'form.action'} eq 'rolepicker') {
1.120 raeburn 2872: if ($can_setacl) {
2873: &role_options_window($r);
2874: } else {
1.138 albertel 2875: &missing_priv($r,$url,'setacl');
1.120 raeburn 2876: }
1.82 albertel 2877: } elsif ($env{'form.createdir'}) {
1.120 raeburn 2878: if ($can_upload) {
1.191 raeburn 2879: &createdir($r,$url,$group);
1.120 raeburn 2880: } else {
1.138 albertel 2881: &missing_priv($r,$url,'upload');
1.120 raeburn 2882: }
1.82 albertel 2883: } elsif ($env{'form.lockinfo'}) {
1.137 albertel 2884: &lock_info($r,$url,$group);
1.24 albertel 2885: } else {
1.226 raeburn 2886: if ($env{'form.action'} eq 'cancel_overwrite') {
2887: if ($can_upload) {
2888: my $formname = 'existingfile';
2889: my $fname = &Apache::lonnet::clean_filename($env{'form.filename'});
2890: $env{'form.'.$formname.'.filename'} = $fname;
1.231 raeburn 2891: my $subdir = $port_path.$env{'form.currentpath'};
2892: $subdir =~ s{(/)$}{};
2893: &Apache::lonnet::userfileupload($formname,'canceloverwrite',$subdir);
1.226 raeburn 2894: }
2895: }
1.24 albertel 2896: my $current_path='/';
1.82 albertel 2897: if ($env{'form.currentpath'}) {
2898: $current_path = $env{'form.currentpath'};
1.24 albertel 2899: }
1.132 raeburn 2900: if ($caller eq 'coursegrp_portfolio') {
2901: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.137 albertel 2902: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
1.132 raeburn 2903: }
1.233 raeburn 2904: my ($dirlistref,$listerror) =
2905: &get_dir_list($portfolio_root,$current_path,$group);
2906: if ($listerror eq 'no_such_dir'){
1.46 albertel 2907: # two main reasons for this:
2908: # 1) never been here, so directory structure not created
2909: # 2) back-button navigation after deleting a directory
2910: if ($current_path eq '/'){
1.100 albertel 2911: &Apache::lonnet::mkdiruserfile($uname,$udom,
1.138 albertel 2912: &get_port_path());
1.46 albertel 2913: } else {
2914: # some directory that snuck in get rid of the directory
2915: # from the recent pulldown, just in case
2916: &Apache::lonhtmlcommon::remove_recent('portfolio',
2917: [$current_path]);
2918: $current_path = '/'; # force it back to the root
2919: }
2920: # now grab the directory list again, for the first time
1.233 raeburn 2921: ($dirlistref,$listerror) =
2922: &get_dir_list($portfolio_root,$current_path,$group);
1.43 banghart 2923: }
1.46 albertel 2924: # need to know if directory is empty so it can be removed if desired
1.233 raeburn 2925: my $is_empty;
2926: if ($listerror eq 'empty') {
2927: $is_empty = 1;
2928: } elsif (ref($dirlistref) eq 'ARRAY') {
2929: if ((scalar(@{$dirlistref}) == 2) && ($dirlistref->[0] =~ /^\.+\&/)
2930: && ($dirlistref->[1] =~ /^\.+\&/)) {
2931: $is_empty = 1;
2932: }
2933: }
2934: &display_common($r,$url,$current_path,$is_empty,$dirlistref,
1.206 raeburn 2935: $can_upload,$group);
1.233 raeburn 2936: &display_directory($r,$url,$current_path,$is_empty,$dirlistref,$group,
1.137 albertel 2937: $can_upload,$can_modify,$can_delete,$can_setacl);
1.30 banghart 2938: }
1.226 raeburn 2939: $r->print(&Apache::loncommon::end_page());
1.90 albertel 2940: return OK;
1.2 banghart 2941: }
1.120 raeburn 2942:
1.1 banghart 2943: 1;
2944: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>