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