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