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