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