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