Annotation of loncom/interface/portfolio.pm, revision 1.222
1.125 albertel 1: # The LearningOnline Network
2: # portfolio browser
3: #
1.222 ! raeburn 4: # $Id: portfolio.pm,v 1.221 2010/03/26 22:27:06 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.16 banghart 66: # receives a file name and path stub from username/userfiles/portfolio/
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'));
101: $r->print(&display_usage($group));
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.206 raeburn 115: $r->print('<div>'.$help_portfolio);
1.199 bisitz 116: # Upload File
117: $r->print('<div class="LC_left_float">'
118: .'<form method="post" enctype="multipart/form-data" action="'.$escuri.'">'
119: .'<fieldset>'
120: .'<legend>'.$lt{'upload_label'}.'</legend>'
121: .$groupitem
122: .'<input name="uploaddoc" type="file" />'
123: .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
124: .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
125: .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
126: .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
127: .'<input type="submit" name="storeupl" value="'.$lt{'upload'}.'" />'
128: .$help_fileupload
129: .$parse_check
130: .'</fieldset>'
131: .'</form>'
132: .'</div>'
133: );
134: # Create Subdirectory
135: $r->print('<div class="LC_left_float">'
136: .'<form method="post" action="'.$escuri.'">'
137: .'<fieldset>'
138: .'<legend>'.$lt{'createdir_label'}.'</legend>'
1.204 raeburn 139: .'<input name="newdir" type="text" />'.$groupitem
1.199 bisitz 140: .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
141: .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
142: .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
143: .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
144: .'<input type="submit" name="createdir" value="'.$lt{'createdir'}.'" />'
145: .$help_createdir
146: .'</fieldset>'
147: .'</form>'
148: .'</div>'
149: );
150: $r->print('</div>');
151: } # end "if can_upload"
152:
1.24 albertel 153: my @tree = split (/\//,$current_path);
1.150 banghart 154: my %anchor_fields = (
1.149 banghart 155: 'selectfile' => $port_path,
156: 'currentpath' => '/',
157: 'mode' => $env{"form.mode"},
158: 'fieldname' => $env{"form.fieldname"},
159: 'continue' => $env{"form.continue"}
160: );
1.215 bisitz 161: $r->print('<br clear="all" />');
1.149 banghart 162: $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
1.19 banghart 163: if (@tree > 1){
1.176 albertel 164: my $newCurrentPath = '/';
1.19 banghart 165: for (my $i = 1; $i< @tree; $i++){
166: $newCurrentPath .= $tree[$i].'/';
1.150 banghart 167: my %anchor_fields = (
1.149 banghart 168: 'selectfile' => $tree[$i],
1.176 albertel 169: 'currentpath' => $newCurrentPath,
1.149 banghart 170: 'mode' => $env{"form.mode"},
171: 'fieldname' => $env{"form.fieldname"},
172: 'continue' => $env{"form.continue"}
173: );
174: $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
1.19 banghart 175: }
176: }
1.117 albertel 177: $r->print('</span>');
1.168 albertel 178: $r->print(&Apache::loncommon::help_open_topic('Portfolio ChangeDirectory'));
1.94 raeburn 179: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
1.137 albertel 180: $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.&group_args());
1.94 raeburn 181: $r->print('">'.
182: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
1.22 albertel 183: 'this.form.submit();'));
1.21 banghart 184: $r->print("</form>");
1.48 banghart 185: }
1.137 albertel 186:
1.206 raeburn 187: sub display_usage {
188: my ($group) = @_;
189: my $disk_quota = &get_quota($group);
190: my $getpropath = 1;
191: my $portfolio_root = &get_portfolio_root();
192: my ($uname,$udom) = &get_name_dom($group);
193: my $current_disk_usage =
194: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
195: my $usage = $current_disk_usage/1000;
196: my $quota = $disk_quota/1000;
197: my $percent;
198: if ($disk_quota == 0) {
199: $percent = 100.0;
200: } else {
201: $percent = 100*($current_disk_usage/$disk_quota);
202: }
203: $usage = sprintf("%.2f",$usage);
204: $quota = sprintf("%.2f",$quota);
205: $percent = sprintf("%.0f",$percent);
206: my ($color,$cssclass);
207: if ($percent <= 60) {
208: $color = '#00A000';
209: } elsif ($percent > 60 && $percent < 90) {
210: $color = '#FFD300';
211: $cssclass = 'class="LC_warning"';
212: } elsif( $percent >= 90) {
213: $color = '#FF0000';
214: $cssclass = 'class="LC_error"';
215: }
216: my $prog_width = $percent;
217: if ($prog_width > 100) {
218: $prog_width = 100;
219: }
220: my $disk_meter = '
221: <div id="meter1" align="left" '.$cssclass.'>'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB <span style="font-weight:bold;">('.$percent.'%)</span>',$quota.' MB')."\n".
222: ' <div id="meter2" style="display:block; margin-top:5px; margin-bottom:5px; margin-left:0px; margin-right:0px; width:400px; border:1px solid #000000; height:10px;">'."\n".
223: ' <div id="meter3" style="display:block; background-color:'.$color.'; width:'.$prog_width.'%; height:10px; color:#000000; margin:0px;"></div>'."\n".
224: ' </div>'."\n".
225: ' </div>';
1.218 raeburn 226: return &Apache::loncommon::head_subbox($disk_meter);
1.206 raeburn 227: }
228:
1.134 banghart 229: sub display_directory_line {
1.156 albertel 230: my ($r,$select_mode, $filename, $mtime, $size, $css_class,
1.137 albertel 231: $line, $access_controls, $curr_access, $now, $version_flag,
1.140 banghart 232: $href_location, $url, $current_path, $access_admin_text, $versions)=@_;
1.156 albertel 233:
234: my $fullpath = &prepend_group($current_path.$filename);
1.197 bisitz 235: $r->print(&Apache::loncommon::start_data_table_row());
1.153 banghart 236: $r->print($line); # contains first two cells of table
1.155 banghart 237: my $lock_info;
1.156 albertel 238: if ($version_flag) { # versioned can't be versioned, so TRUE when root file
1.213 droeschl 239: $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" class="LC_fileicon" /></td>');
1.156 albertel 240: $r->print('<td>'.$version_flag.'</td>');
1.153 banghart 241: } else { # this is a graded or handed back file
1.191 raeburn 242: my ($user,$domain) = &get_name_dom($env{'form.group'});
1.154 banghart 243: my $permissions_hash = &Apache::lonnet::get_portfile_permissions($domain,$user);
1.156 albertel 244: if (defined($$permissions_hash{$fullpath})) {
245: foreach my $array_item (@{$$permissions_hash{$fullpath}}) {
1.155 banghart 246: if (ref($array_item) eq 'ARRAY') {
1.156 albertel 247: if ($$array_item[-1] eq 'handback') {
1.155 banghart 248: $lock_info = 'Handback';
1.156 albertel 249: } elsif ($$array_item[-1] eq 'graded') {
1.155 banghart 250: $lock_info = 'Graded';
1.154 banghart 251: }
1.155 banghart 252: }
1.154 banghart 253: }
254: }
1.156 albertel 255: if ($lock_info) {
256: my %anchor_fields = ('lockinfo' => $fullpath);
1.161 banghart 257: if ($versions) { # hold the folder open
258: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($fullpath);
259: $fname =~ s|^/||;
260: $anchor_fields{'showversions'} = $fname.'.'.$extension;
261: }
1.156 albertel 262: $lock_info = &make_anchor(undef,\%anchor_fields,$lock_info);
263: }
264: $r->print('<td colspan="2">'.$lock_info.'</td>');
1.153 banghart 265: }
266: # $r->print('<td>'.$$version_flag{$filename}.'</td><td>');
267: $r->print('<td>'.&make_anchor($href_location.$filename,undef,$filename).'</td>');
1.137 albertel 268: $r->print('<td>'.$size.'</td>');
269: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
270: if ($select_mode ne 'true') {
1.197 bisitz 271: $r->print('<td class="'.$css_class.'"> </td>'); # Display status
272: $r->print('<td><span class="LC_nobreak">'
273: .&mt($curr_access).' '
274: );
1.152 albertel 275: my %anchor_fields = (
1.150 banghart 276: 'access' => $filename,
277: 'currentpath' => $current_path
278: );
279: $r->print(&make_anchor($url, \%anchor_fields, $access_admin_text).'</span></td>');
1.197 bisitz 280: } else {
281: $r->print('<td class="'.$css_class.'"> </td>'); # Display status
1.137 albertel 282: }
1.197 bisitz 283: $r->print(&Apache::loncommon::end_data_table_row().$/);
1.134 banghart 284: }
1.137 albertel 285:
1.48 banghart 286: sub display_directory {
1.138 albertel 287: my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
1.137 albertel 288: $can_modify,$can_delete,$can_setacl)=@_;
1.48 banghart 289: my $iconpath= $r->dir_config('lonIconsURL') . "/";
290: my $display_out;
1.77 banghart 291: my $select_mode;
292: my $checked_files;
1.138 albertel 293: my $port_path = &get_port_path();
1.191 raeburn 294: my ($uname,$udom) = &get_name_dom($group);
1.120 raeburn 295: my $access_admin_text = &mt('View Status');
296: if ($can_setacl) {
297: $access_admin_text = &mt('View/Change Status');
298: }
299:
1.102 raeburn 300: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
301: $uname);
302: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
303: $current_permissions,$group);
304: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
305: my $now = time;
1.170 raeburn 306: if ($env{"form.mode"} eq 'selectfile') {
1.77 banghart 307: &select_files($r);
1.94 raeburn 308: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
1.77 banghart 309: $select_mode = 'true';
310: }
1.120 raeburn 311: if ($is_empty && ($current_path ne '/') && $can_delete) {
1.137 albertel 312: $display_out = '<form method="post" action="'.$url.'">'.
313: &group_form_data().
1.30 banghart 314: '<input type="hidden" name="action" value="deletedir" />'.
1.199 bisitz 315: '<p>'.
1.30 banghart 316: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
1.199 bisitz 317: '</p>'.
1.30 banghart 318: '<input type="hidden" name="selectfile" value="" />'.
319: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
320: '</form>';
321:
1.48 banghart 322: $r->print($display_out);
1.31 albertel 323: return;
324: }
1.77 banghart 325: if ($select_mode eq 'true') {
1.113 albertel 326: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
1.197 bisitz 327: $r->print(&Apache::loncommon::start_data_table()
328: .&Apache::loncommon::start_data_table_header_row()
329: .'<th>'.&mt('Select').'</th>'
330: .'<th> </th><th> </th>'
331: .'<th>'.&mt('Name').'</th>'
332: .'<th>'.&mt('Size').'</th>'
333: .'<th>'.&mt('Last Modified').'</th>'
334: .'<th> </th>'
335: .&Apache::loncommon::end_data_table_header_row()
336: );
1.77 banghart 337: } else {
1.113 albertel 338: $r->print('<form method="post" action="'.$url.'">');
1.168 albertel 339: $r->print(&Apache::loncommon::help_open_topic('Portfolio FileList',
1.187 bisitz 340: &mt('Using the portfolio file list')));
1.197 bisitz 341: $r->print(&Apache::loncommon::start_data_table()
342: .&Apache::loncommon::start_data_table_header_row()
1.187 bisitz 343: .'<th colspan="2">'.&mt('Actions'). &Apache::loncommon::help_open_topic('Portfolio FileAction').'</th>'
344: .'<th> </th><th> </th>'
345: .'<th>'.&mt('Name').&Apache::loncommon::help_open_topic('Portfolio OpenFile').'</th>'
346: .'<th>'.&mt('Size').'</th>'
347: .'<th>'.&mt('Last Modified').'</th>'
1.197 bisitz 348: .'<th> </th>'
1.187 bisitz 349: .'<th>'.&mt('Current Access Status').&Apache::loncommon::help_open_topic('Portfolio ShareFile').'</th>'
1.197 bisitz 350: .&Apache::loncommon::end_data_table_header_row());
1.94 raeburn 351: }
1.137 albertel 352: $r->print("\n".&group_form_data()."\n");
353:
1.94 raeburn 354: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
355: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
1.105 banghart 356: my @dir_lines;
357: my %versioned;
1.140 banghart 358: foreach my $dir_line (sort
1.26 albertel 359: {
360: my ($afile)=split('&',$a,2);
361: my ($bfile)=split('&',$b,2);
362: return (lc($afile) cmp lc($bfile));
363: } (@$dir_list)) {
1.140 banghart 364: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
1.77 banghart 365: $filename =~ s/\s+$//;
1.105 banghart 366: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
367: if ($version) {
1.156 albertel 368: my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
369: push(@{ $versioned{$fullpath} },
370: [$filename,$dom,$testdir,$size,$mtime,$obs,]);
1.131 banghart 371: } else {
372: push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
1.105 banghart 373: }
374: }
1.140 banghart 375: foreach my $dir_line (@dir_lines) {
376: my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
1.105 banghart 377: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
1.93 albertel 378: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
1.156 albertel 379: my $version_flag;
1.131 banghart 380: my $show_versions;
1.156 albertel 381: my $fullpath = &prepend_group($current_path.$filename);
1.162 banghart 382: if ($env{'form.showversions'} =~ /$filename/) {
1.131 banghart 383: $show_versions = 'true';
384: }
1.156 albertel 385: if (exists($versioned{$fullpath})) {
1.152 albertel 386: my %anchor_fields = (
1.156 albertel 387: 'selectfile' => $fullpath,
1.150 banghart 388: 'continue' => 'false',
389: 'currentpath' => $current_path,
390: );
1.134 banghart 391: if ($show_versions) {
1.162 banghart 392: # Must preserve other possible showversion files
393: my $version_remainder = $env{'form.showversions'};
394: $version_remainder =~ s/$filename//g;
395: $anchor_fields{'showversions'} = $version_remainder;
1.156 albertel 396: $version_flag = &make_anchor('portfolio',\%anchor_fields,
1.150 banghart 397: '<img class="LC_icon" alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" />');
1.134 banghart 398: } else {
1.162 banghart 399: # allow multiple files to show versioned
400: $anchor_fields{'showversions'} = $env{'form.showversions'}.','.$filename;
1.156 albertel 401: $version_flag = &make_anchor('portfolio',\%anchor_fields,
1.150 banghart 402: '<img class="LC_icon" alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" />');
1.134 banghart 403: }
1.129 banghart 404: } else {
1.156 albertel 405: $version_flag = ' ';
1.129 banghart 406: }
1.23 albertel 407: if ($dirptr&$testdir) {
1.197 bisitz 408: my $colspan_folder='';
409: my $colspan_fill='';
1.77 banghart 410: if ($select_mode eq 'true'){
1.197 bisitz 411: $colspan_fill=' colspan="3"';
412: } else {
413: $colspan_folder=' colspan="2"';
414: $colspan_fill=' colspan="4"';
1.64 banghart 415: }
1.197 bisitz 416: $r->print('<tr class="LC_browser_folder">');
1.213 droeschl 417: $r->print('<td'.$colspan_folder.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'navmap.folder.closed.gif" class="LC_fileicon" /></td>'
1.197 bisitz 418: .'<td>'.&mt('Go to ...').'</td>');
1.152 albertel 419: my %anchor_fields = (
1.149 banghart 420: 'selectfile' => $filename.'/',
421: 'currentpath' => $current_path.$filename.'/',
422: 'mode' => $env{"form.mode"},
423: 'fieldname' => $env{"form.fieldname"},
424: 'continue' => $env{"form.continue"}
425: );
1.197 bisitz 426: $r->print('<td>'.$version_flag.'</td>'
427: .'<td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>');
428: $r->print('<td'.$colspan_fill.'> </td>');
1.47 banghart 429: $r->print('</tr>');
430: } else {
1.116 albertel 431: my $css_class = 'LC_browser_file';
432: my $line;
1.124 albertel 433: if ($select_mode eq 'true') {
1.116 albertel 434: $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
435: if ($$checked_files{$filename} eq 'selected') {
1.197 bisitz 436: $line.=' checked="checked" ';
1.77 banghart 437: }
1.116 albertel 438: $line.=' /></td>';
1.77 banghart 439: } else {
1.103 raeburn 440: if (exists $locked_files{$fullpath}) {
1.152 albertel 441: my %anchor_fields = (
1.156 albertel 442: 'lockinfo' => $fullpath
1.150 banghart 443: );
1.188 bisitz 444: $line.='<td colspan="2">'.&make_anchor($url,\%anchor_fields,&mt('Locked')).'</td>';
1.116 albertel 445: $css_class= 'LC_browser_file_locked';
1.77 banghart 446: } else {
1.120 raeburn 447: if (!$can_modify) {
448: $line .= '<td colspan="2">';
449: } else {
450: $line .= '<td>';
451: }
452: if ($can_delete) {
453: $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
454: }
455: if ($can_modify) {
1.219 raeburn 456: my $cat='<img class="LC_icon" alt="'.&mt('Metadata').'" title="'.&mt('Metadata').'" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').'" />';
1.152 albertel 457: my %anchor_fields = (
1.150 banghart 458: 'rename' => $filename,
459: currentpath => $current_path
460: );
1.188 bisitz 461: $line .= &make_anchor($url,\%anchor_fields,&mt('Rename'));
1.159 banghart 462: $line .= '</td><td>'.&make_anchor($href_edit_location.$filename.'.meta',\%anchor_fields,$cat);
1.150 banghart 463: # '<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
1.120 raeburn 464: }
465: $line .= '</td>';
1.77 banghart 466: }
1.61 banghart 467: }
1.124 albertel 468: my $curr_access;
469: if ($select_mode ne 'true') {
470: my $pub_access = 0;
471: my $guest_access = 0;
472: my $cond_access = 0;
473: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
474: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
475: if (($now > $start) && (!$end || $end > $now)) {
476: if ($scope eq 'public') {
477: $pub_access = 1;
478: } elsif ($scope eq 'guest') {
479: $guest_access = 1;
480: } else {
481: $cond_access = 1;
482: }
483: }
484: }
485: if (!$pub_access && !$guest_access && !$cond_access) {
486: $curr_access = &mt('Private');
487: } else {
488: my @allaccesses;
489: if ($pub_access) {
490: push(@allaccesses,&mt('Public'));
491: }
492: if ($guest_access) {
493: push(@allaccesses,&mt('Passphrase-protected'));
494: }
495: if ($cond_access) {
496: push(@allaccesses,&mt('Conditional'));
497: }
498: $curr_access = join('+ ',@allaccesses);
499: }
500: }
1.156 albertel 501: &display_directory_line($r,$select_mode, $filename, $mtime, $size, $css_class, $line,
502: \%access_controls, $curr_access,$now, $version_flag, $href_location,
1.140 banghart 503: $url, $current_path, $access_admin_text);
1.134 banghart 504: if ($show_versions) {
1.156 albertel 505: foreach my $dir_line (@{ $versioned{$fullpath} }) {
506: my ($v_filename,$dom,$testdir,$size,$mtime,$obs) =
507: @$dir_line;
1.143 banghart 508: $line = '<td colspan="2"> </td>';
1.156 albertel 509: &display_directory_line($r,$select_mode, $v_filename, $mtime, $size,
510: $css_class, $line, \%access_controls, $curr_access, $now,
511: undef, $href_location, $url, $current_path, $access_admin_text, 1);
1.140 banghart 512: }
1.134 banghart 513: }
1.47 banghart 514: }
515: }
516: }
1.77 banghart 517: if ($select_mode eq 'true') {
1.197 bisitz 518: $r->print(&Apache::loncommon::end_data_table().'
1.127 albertel 519: <input type="hidden" name="continue" value="true" />
520: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
521: <input type="hidden" name="mode" value="selectfile" />
1.198 bisitz 522: <p>
523: <input type="submit" name="submit" value="'.&mt('Select checked files, and continue selecting').'" /><br />
1.214 bisitz 524: <input type="button" name="doit" onClick="finishSelect();" value="'.&mt('Select checked files, and close window').'" />
1.198 bisitz 525: </p>
1.48 banghart 526: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77 banghart 527: </form>');
528: } else {
1.197 bisitz 529: $r->print(&Apache::loncommon::end_data_table());
1.120 raeburn 530: if ($can_delete) {
531: $r->print('
1.199 bisitz 532: <p>
1.196 schafran 533: <input type="submit" name="doit" value="'.&mt('Delete Selected').'" />'.
1.168 albertel 534: &Apache::loncommon::help_open_topic('Portfolio DeleteFile').'
1.199 bisitz 535: </p>
1.77 banghart 536: <input type="hidden" name="action" value="delete" />
537: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.120 raeburn 538: </form>'
539: );
540: }
1.77 banghart 541: }
1.47 banghart 542: }
1.72 banghart 543:
1.24 albertel 544: sub open_form {
1.94 raeburn 545: my ($r,$url)=@_;
1.65 banghart 546: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.102 raeburn 547: $r->print('<form name="portform" method="post" action="'.$url.'">');
1.24 albertel 548: $r->print('<input type="hidden" name="action" value="'.
1.82 albertel 549: $env{'form.action'}.'" />');
1.24 albertel 550: $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65 banghart 551: foreach (@files) {
552: $r->print('<input type="hidden" name="selectfile" value="'.
553: $_.'" />');
554: }
1.24 albertel 555: $r->print('<input type="hidden" name="currentpath" value="'.
1.82 albertel 556: $env{'form.currentpath'}.'" />');
1.24 albertel 557: }
558:
559: sub close_form {
1.137 albertel 560: my ($r,$url,$button_text)=@_;
1.108 raeburn 561: if (!defined($button_text)) {
562: $button_text = {
563: 'continue' => &mt('Continue'),
564: 'cancel' => &mt('Cancel'),
565: };
566: }
1.138 albertel 567: $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
1.137 albertel 568: $r->print(&group_form_data().'</p></form>');
1.112 albertel 569: $r->print('<form action="'.$url.'" method="post">
1.24 albertel 570: <p>
571: <input type="hidden" name="currentpath" value="'.
1.137 albertel 572: $env{'form.currentpath'}.'" />'.
573: &group_form_data());
1.108 raeburn 574: $r->print("\n".' <input type="submit" value="'.$button_text->{'cancel'}.'" />
1.94 raeburn 575: </p></form>');
1.24 albertel 576: }
577:
578: sub display_file {
1.27 albertel 579: my ($path,$filename)=@_;
1.65 banghart 580: my $display_file_text;
1.116 albertel 581: my $file_start='<span class="LC_filename">';
582: my $file_end='</span>';
1.82 albertel 583: if (!defined($path)) { $path=$env{'form.currentpath'}; }
1.65 banghart 584: if (!defined($filename)) {
1.82 albertel 585: $filename=$env{'form.selectfile'};
1.116 albertel 586: $display_file_text = $file_start.$path.$filename.$file_end;
1.65 banghart 587: } elsif (ref($filename) eq "ARRAY") {
1.116 albertel 588: foreach my $file (@$filename) {
589: $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
1.65 banghart 590: }
591: } elsif (ref($filename) eq "SCALAR") {
1.116 albertel 592: $display_file_text = $file_start.$path.$$filename.$file_end;
593: } else {
594: $display_file_text = $file_start.$path.$filename.$file_end;
1.65 banghart 595: }
596: return $display_file_text;
1.24 albertel 597: }
598:
599: sub done {
1.137 albertel 600: my ($message,$url)=@_;
1.76 banghart 601: unless (defined $message) {
602: $message='Done';
603: }
1.153 banghart 604: my %anchor_fields = (
1.161 banghart 605: 'showversions' => $env{'form.showversions'},
1.153 banghart 606: 'currentpath' => $env{'form.currentpath'},
607: 'fieldname' => $env{'form.fieldname'},
608: 'mode' => $env{'form.mode'}
609: );
610: my $result = '<h3>'.&make_anchor($url,\%anchor_fields,&mt($message)).'</h3>';
1.94 raeburn 611: return $result;
1.24 albertel 612: }
613:
614: sub delete {
1.191 raeburn 615: my ($r,$url,$group)=@_;
1.55 banghart 616: my @check;
1.82 albertel 617: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.138 albertel 618: $file_name = &prepend_group($file_name);
1.65 banghart 619: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.191 raeburn 620: my ($uname,$udom) = &get_name_dom($group);
1.94 raeburn 621: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.190 raeburn 622: $r->print(&mt('The file is locked and cannot be deleted.').'<br />');
1.137 albertel 623: $r->print(&done('Back',$url));
1.55 banghart 624: } else {
1.66 banghart 625: if (scalar(@files)) {
1.94 raeburn 626: &open_form($r,$url);
1.188 bisitz 627: $r->print('<p>'.&mt('Delete [_1]?',&display_file(undef,\@files)).'</p>');
1.137 albertel 628: &close_form($r,$url);
1.66 banghart 629: } else {
630: $r->print("No file was checked to delete.<br />");
1.137 albertel 631: $r->print(&done(undef,$url));
1.66 banghart 632: }
1.55 banghart 633: }
1.24 albertel 634: }
635:
636: sub delete_confirmed {
1.164 raeburn 637: my ($r,$url,$group)=@_;
1.65 banghart 638: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
639: my $result;
1.191 raeburn 640: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 641: my $port_path = &get_port_path();
1.164 raeburn 642: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
643: $uname);
1.65 banghart 644: foreach my $delete_file (@files) {
1.94 raeburn 645: $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.82 albertel 646: $env{'form.currentpath'}.
1.65 banghart 647: $delete_file);
648: if ($result ne 'ok') {
1.187 bisitz 649: $r->print('<span class="LC_error">'
650: .&mt('An error occurred ([_1]) while trying to delete [_2].'
651: ,$result,&display_file(undef, $delete_file))
652: .'</span><br /><br />');
1.164 raeburn 653: } else {
654: $r->print(&mt('File: [_1] deleted.',
655: &display_file(undef,$delete_file)));
656: my $file_name = $env{'form.currentpath'}.$delete_file;
657: $file_name = &prepend_group($file_name);
658: my %access_controls =
659: &Apache::lonnet::get_access_controls($current_permissions,
660: $group,$file_name);
661: if (keys(%access_controls) > 0) {
662: my %changes;
1.166 raeburn 663: foreach my $key (keys(%{$access_controls{$file_name}})) {
1.164 raeburn 664: $changes{'delete'}{$key} = 1;
665: }
666: if (keys(%changes) > 0) {
667: my ($outcome,$deloutcome,$new_values,$translation) =
668: &Apache::lonnet::modify_access_controls($file_name,\%changes,
669: $udom,$uname);
670: if ($outcome ne 'ok') {
1.182 albertel 671: $r->print('<br />'.&mt("An error occurred ([_1]) while ".
1.165 albertel 672: "trying to delete access controls for the file.",$outcome).
1.166 raeburn 673: '</span><br /><br />');
1.164 raeburn 674: } else {
675: if ($deloutcome eq 'ok') {
1.166 raeburn 676: $r->print('<br />'.&mt('Access controls also deleted for the file.').'<br /><br />');
1.164 raeburn 677: } else {
1.165 albertel 678: $r->print('<span class="LC_error">'.'<br />'.
1.182 albertel 679: &mt("An error occurred ([_1]) while ".
1.165 albertel 680: "trying to delete access controls for the file.",$deloutcome).
1.166 raeburn 681: '</span><br /><br />');
1.164 raeburn 682: }
683: }
684: }
685: }
1.65 banghart 686: }
1.24 albertel 687: }
1.137 albertel 688: $r->print(&done(undef,$url));
1.24 albertel 689: }
690:
1.30 banghart 691: sub delete_dir {
1.137 albertel 692: my ($r,$url)=@_;
1.94 raeburn 693: &open_form($r,$url);
1.188 bisitz 694: $r->print('<p>'.&mt('Delete [_1]?',&display_file()).'</p>');
1.137 albertel 695: &close_form($r,$url);
1.30 banghart 696: }
697:
698: sub delete_dir_confirmed {
1.191 raeburn 699: my ($r,$url,$group)=@_;
1.82 albertel 700: my $directory_name = $env{'form.currentpath'};
1.81 albertel 701: $directory_name =~ s|/$||; # remove any trailing slash
1.191 raeburn 702: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 703: my $namespace = &get_namespace();
704: my $port_path = &get_port_path();
1.94 raeburn 705: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.30 banghart 706: $directory_name);
1.32 banghart 707:
1.30 banghart 708: if ($result ne 'ok') {
1.188 bisitz 709: $r->print('<span class="LC_error">'
710: .&mt('An error occurred (dir) ([_1]) while trying to delete [_2].'
711: ,$result,$directory_name)
712: .'</span><br />');
1.32 banghart 713: } else {
1.41 banghart 714: # now remove from recent
1.94 raeburn 715: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
1.32 banghart 716: my @dirs = split m!/!, $directory_name;
717: $directory_name='/';
718: for (my $i=1; $i < (@dirs - 1); $i ++){
719: $directory_name .= $dirs[$i].'/';
720: }
1.82 albertel 721: $env{'form.currentpath'} = $directory_name;
1.30 banghart 722: }
1.137 albertel 723: $r->print(&done(undef,$url));
1.30 banghart 724: }
725:
1.24 albertel 726: sub rename {
1.191 raeburn 727: my ($r,$url,$group)=@_;
1.82 albertel 728: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
1.191 raeburn 729: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 730: $file_name = &prepend_group($file_name);
1.94 raeburn 731: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.169 albertel 732: $r->print("The file is locked and cannot be renamed.<br />");
1.137 albertel 733: $r->print(&done(undef,$url));
1.55 banghart 734: } else {
1.94 raeburn 735: &open_form($r,$url);
1.188 bisitz 736: $r->print('<p>'.&mt('Rename [_1] to [_2]?', &display_file()
1.204 raeburn 737: , '<input name="filenewname" type="text" size="50" />').'</p>');
1.137 albertel 738: &close_form($r,$url);
1.55 banghart 739: }
1.24 albertel 740: }
741:
742: sub rename_confirmed {
1.164 raeburn 743: my ($r,$url,$group)=@_;
1.82 albertel 744: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.191 raeburn 745: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 746: my $port_path = &get_port_path();
1.27 albertel 747: if ($filenewname eq '') {
1.116 albertel 748: $r->print('<span class="LC_error">'.
1.27 albertel 749: &mt("Error: no valid filename was provided to rename to.").
1.116 albertel 750: '</span><br />');
1.137 albertel 751: $r->print(&done(undef,$url));
1.27 albertel 752: return;
753: }
1.164 raeburn 754: my $chg_access;
1.27 albertel 755: my $result=
1.94 raeburn 756: &Apache::lonnet::renameuserfile($uname,$udom,
757: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
758: $port_path.$env{'form.currentpath'}.$filenewname);
1.164 raeburn 759: if ($result eq 'ok') {
760: $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
761: } else {
1.116 albertel 762: $r->print('<span class="LC_error">'.
1.189 raeburn 763: &mt('An error occurred ([_1]) while trying to rename [_2] to [_3].'
1.188 bisitz 764: ,$result,&display_file(),&display_file('',$filenewname))
765: .'</span><br />');
1.164 raeburn 766: return;
1.27 albertel 767: }
1.82 albertel 768: if ($filenewname ne $env{'form.filenewname'}) {
1.116 albertel 769: $r->print(&mt("The new file name was changed from:<br />[_1] to [_2]",
770: '<strong>'.&display_file('',$env{'form.filenewname'}).'</strong>',
771: '<strong>'.&display_file('',$filenewname).'</strong>'));
1.66 banghart 772: }
1.164 raeburn 773: $r->print($chg_access);
1.137 albertel 774: $r->print(&done(undef,$url));
1.27 albertel 775: }
1.102 raeburn 776:
1.164 raeburn 777: sub access_for_renamed {
778: my ($filenewname,$group,$udom,$uname) = @_;
779: my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'};
780: $oldfile = &prepend_group($oldfile);
781: my $newfile = $env{'form.currentpath'}.$filenewname;
782: $newfile = &prepend_group($newfile);
783: my $current_permissions =
1.165 albertel 784: &Apache::lonnet::get_portfile_permissions($udom,$uname);
1.164 raeburn 785: my %access_controls =
1.165 albertel 786: &Apache::lonnet::get_access_controls($current_permissions,
787: $group,$oldfile);
1.164 raeburn 788: my $chg_text;
789: if (keys(%access_controls) > 0) {
790: my %change_old;
791: my %change_new;
1.165 albertel 792: foreach my $key (keys(%{$access_controls{$oldfile}})) {
1.164 raeburn 793: $change_old{'delete'}{$key} = 1;
794: $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key};
795: }
796: my ($outcome,$deloutcome,$new_values,$translation) =
797: &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
1.165 albertel 798: $udom,$uname);
1.164 raeburn 799: if ($outcome ne 'ok') {
1.182 albertel 800: $chg_text ='<br /><br />'.&mt("An error occurred ([_1]) while ".
1.165 albertel 801: "trying to delete access control records for the old name.",$outcome).
1.164 raeburn 802: '</span><br />';
803: } else {
804: if ($deloutcome ne 'ok') {
1.165 albertel 805: $chg_text = '<br /><br /><span class="LC_error"><br />'.
1.182 albertel 806: &mt("An error occurred ([_1]) while ".
1.165 albertel 807: "trying to delete access control records for the old name.",$deloutcome).
808: '</span><br />';
1.164 raeburn 809: }
810: }
811: ($outcome,$deloutcome,$new_values,$translation) =
812: &Apache::lonnet::modify_access_controls($newfile,\%change_new,
813: $udom,$uname);
814: if ($outcome ne 'ok') {
1.165 albertel 815: $chg_text .= '<br /><br />'.
1.182 albertel 816: &mt("An error occurred ([_1]) while ".
1.165 albertel 817: "trying to update access control records for the new name.",$outcome).
1.164 raeburn 818: '</span><br />';
819: }
820: if ($chg_text eq '') {
821: $chg_text = '<br /><br />'.&mt('Access controls updated to reflect the name change.');
822: }
823: }
824: return $chg_text;
825: }
826:
1.104 raeburn 827: sub display_access {
1.170 raeburn 828: my ($r,$url,$group,$can_setacl,$port_path,$action) = @_;
1.191 raeburn 829: my ($uname,$udom) = &get_name_dom($group);
1.104 raeburn 830: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
1.138 albertel 831: $file_name = &prepend_group($file_name);
1.104 raeburn 832: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
833: $uname);
834: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
1.120 raeburn 835: my $aclcount = keys(%access_controls);
1.170 raeburn 836: my ($header,$info);
837: if ($action eq 'chgaccess') {
838: $header = '<h3>'.&mt('Allowing others to retrieve file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>';
839: $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.');
840: $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
841: $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
842: $info .= '</li><li>'.&explain_conditionals();
1.174 raeburn 843: $info .= '</li></ul>'.
1.201 raeburn 844: &mt('A listing of files viewable without log-in is available at: ')."<a href=\"/adm/$udom/$uname/aboutme/portfolio\">".&Apache::lonnet::absolute_url($ENV{'SERVER_NAME'})."/adm/$udom/$uname/aboutme/portfolio</a>.<br />";
1.170 raeburn 845: if ($group eq '') {
1.210 weissno 846: $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 847: } else {
848: $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
849: }
1.201 raeburn 850: $info .= "<br /><a href=\"/adm/$udom/$uname/aboutme\">".&Apache::lonnet::absolute_url($ENV{'SERVER_NAME'})."/adm/$udom/$uname/aboutme</a><br />";
1.174 raeburn 851: if ($group ne '') {
852: $info .= &mt("Users with privileges to edit course contents may add a course information page to a course using the 'Course Info' button in DOCS").'<br />';
1.170 raeburn 853: }
854: } else {
855: $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'.
856: &explain_conditionals().'<br />';
1.142 raeburn 857: }
1.120 raeburn 858: if ($can_setacl) {
859: &open_form($r,$url);
860: $r->print($header.$info);
1.187 bisitz 861: $r->print('<br />'.&Apache::loncommon::help_open_topic('Portfolio ShareFile SetAccess', &mt('Help on setting up share access')));
862: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile ChangeSetting', &mt('Help on changing settings')));
863: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile StopAccess', &mt('Help on removing share access')));
1.170 raeburn 864: &access_setting_table($r,$url,$file_name,$access_controls{$file_name},
865: $action);
1.120 raeburn 866: my $button_text = {
1.108 raeburn 867: 'continue' => &mt('Proceed'),
1.188 bisitz 868: 'cancel' => &mt('Return to directory'),
1.108 raeburn 869: };
1.137 albertel 870: &close_form($r,$url,$button_text);
1.120 raeburn 871: } else {
872: $r->print($header);
873: if ($aclcount) {
874: $r->print($info);
875: }
1.137 albertel 876: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
1.120 raeburn 877: }
878: }
879:
1.170 raeburn 880: sub explain_conditionals {
881: return
882: &mt('Conditional files are accessible to logged-in users with accounts in the LON-CAPA network, who satisfy the conditions you set.').'<br />'."\n".
1.221 raeburn 883: &mt('The conditions can include affiliation with a particular course or community, or a user account in a specific domain.').'<br />'."\n".
1.170 raeburn 884: &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.');
885: }
886:
1.120 raeburn 887: sub view_access_settings {
1.137 albertel 888: my ($r,$url,$access_controls,$aclcount) = @_;
1.120 raeburn 889: my ($showstart,$showend);
890: my %todisplay;
891: foreach my $key (sort(keys(%{$access_controls}))) {
892: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
893: $todisplay{$scope}{$key} = $$access_controls{$key};
894: }
895: if ($aclcount) {
1.188 bisitz 896: $r->print('<h4>'.&mt('Current access controls defined for this file:').'</h4>');
1.120 raeburn 897: $r->print(&Apache::loncommon::start_data_table());
898: $r->print(&Apache::loncommon::start_data_table_header_row());
899: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
900: '</th><th>'.&mt('Additional information').'</th>');
901: $r->print(&Apache::loncommon::end_data_table_header_row());
902: my $count = 1;
903: my $chg = 'none';
904: &build_access_summary($r,$count,$chg,%todisplay);
905: $r->print(&Apache::loncommon::end_data_table());
906: } else {
1.189 raeburn 907: $r->print(&mt('No access control settings currently exist for this file.').'<br />');
1.120 raeburn 908: }
1.153 banghart 909: my %anchor_fields = (
910: 'currentpath' => $env{'form.currentpath'}
911: );
1.188 bisitz 912: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory')));
1.120 raeburn 913: return;
1.104 raeburn 914: }
915:
1.120 raeburn 916: sub build_access_summary {
917: my ($r,$count,$chg,%todisplay) = @_;
918: my ($showstart,$showend);
919: my %scope_desc = (
920: public => 'Public',
921: guest => 'Passphrase-protected',
922: domains => 'Conditional: domain-based',
923: users => 'Conditional: user-based',
1.221 raeburn 924: course => 'Conditional: course/community-based',
1.120 raeburn 925: );
1.170 raeburn 926: my @allscopes = ('public','guest','domains','users','course');
1.120 raeburn 927: foreach my $scope (@allscopes) {
928: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
929: next;
930: }
931: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
932: if ($count) {
933: $r->print(&Apache::loncommon::start_data_table_row());
934: }
935: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
936: my $content = $todisplay{$scope}{$key};
937: if ($chg eq 'delete') {
938: $showstart = &mt('Deleted');
939: $showend = $showstart;
940: } else {
941: $showstart = localtime($start);
942: if ($end == 0) {
943: $showend = &mt('No end date');
944: } else {
945: $showend = localtime($end);
946: }
947: }
948: $r->print('<td>'.&mt($scope_desc{$scope}));
1.221 raeburn 949: my $crstype;
1.170 raeburn 950: if ($scope eq 'course') {
1.120 raeburn 951: if ($chg ne 'delete') {
952: my $cid = $content->{'domain'}.'_'.$content->{'number'};
953: my %course_description = &Apache::lonnet::coursedescription($cid);
954: $r->print('<br />('.$course_description{'description'}.')');
1.221 raeburn 955: $crstype = 'Course';
956: if ($course_description{'type'} ne '') {
957: $crstype = $course_description{'type'};
958: }
1.120 raeburn 959: }
960: }
961: $r->print('</td><td>'.&mt('Start: ').$showstart.
962: '<br />'.&mt('End: ').$showend.'</td><td>');
963: if ($chg ne 'delete') {
964: if ($scope eq 'guest') {
965: $r->print(&mt('Passphrase').': '.$content->{'password'});
1.170 raeburn 966: } elsif ($scope eq 'course') {
1.172 raeburn 967: $r->print('<table width="100%"><tr>');
1.120 raeburn 968: $r->print('<th>'.&mt('Roles').'</th><th>'.
969: &mt('Access').'</th><th>'.
970: &mt('Sections').'</th>');
1.170 raeburn 971: $r->print('<th>'.&mt('Groups').'</th>');
1.120 raeburn 972: $r->print('</tr>');
973: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
974: $r->print('<tr>');
975: foreach my $item ('role','access','section','group') {
976: $r->print('<td>');
977: if ($item eq 'role') {
978: my $role_output;
979: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
980: if ($role eq 'all') {
981: $role_output .= $role.',';
982: } elsif ($role =~ /^cr/) {
983: $role_output .= (split('/',$role))[3].',';
984: } else {
1.221 raeburn 985: $role_output .= &Apache::lonnet::plaintext($role,$crstype).',';
1.120 raeburn 986: }
987: }
988: $role_output =~ s/,$//;
989: $r->print($role_output);
990: } else {
991: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
992: }
1.170 raeburn 993: $r->print('</td>');
1.120 raeburn 994: }
1.170 raeburn 995: $r->print('</tr>');
1.120 raeburn 996: }
1.170 raeburn 997: $r->print('</table>');
1.120 raeburn 998: } elsif ($scope eq 'domains') {
999: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
1000: } elsif ($scope eq 'users') {
1001: my $curr_user_list = &sort_users($content->{'users'});
1002: $r->print(&mt('Users: ').$curr_user_list);
1003: } else {
1004: $r->print(' ');
1005: }
1006: } else {
1007: $r->print(' ');
1008: }
1009: $r->print('</td>');
1010: $r->print(&Apache::loncommon::end_data_table_row());
1011: $count ++;
1012: }
1013: }
1014: }
1015:
1016:
1.104 raeburn 1017: sub update_access {
1.137 albertel 1018: my ($r,$url,$group,$port_path) = @_;
1.104 raeburn 1019: my $totalprocessed = 0;
1020: my %processing;
1021: my %title = (
1.108 raeburn 1022: 'activate' => 'New control(s) added',
1023: 'delete' => 'Existing control(s) deleted',
1024: 'update' => 'Existing control(s) modified',
1.104 raeburn 1025: );
1.108 raeburn 1026: my $changes;
1.104 raeburn 1027: foreach my $chg (sort(keys(%title))) {
1028: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
1029: $totalprocessed += @{$processing{$chg}};
1030: foreach my $num (@{$processing{$chg}}) {
1031: my $scope = $env{'form.scope_'.$num};
1032: my ($start,$end) = &get_dates_from_form($num);
1033: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
1034: if ($chg eq 'delete') {
1035: $$changes{$chg}{$newkey} = 1;
1036: } else {
1037: $$changes{$chg}{$newkey} =
1.108 raeburn 1038: &build_access_record($num,$scope,$start,$end,$chg);
1.104 raeburn 1039: }
1040: }
1041: }
1042: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.142 raeburn 1043: $r->print('<h3>'.&mt('Allowing others to retrieve file: [_1]',
1.133 raeburn 1044: $port_path.$file_name).'</h3>'."\n");
1.138 albertel 1045: $file_name = &prepend_group($file_name);
1.191 raeburn 1046: my ($uname,$udom) = &get_name_dom($group);
1.104 raeburn 1047: my ($errors,$outcome,$deloutcome,$new_values,$translation);
1048: if ($totalprocessed) {
1049: ($outcome,$deloutcome,$new_values,$translation) =
1.108 raeburn 1050: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
1051: $uname);
1.104 raeburn 1052: }
1.108 raeburn 1053: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1054: $uname);
1.109 albertel 1055: my %access_controls =
1056: &Apache::lonnet::get_access_controls($current_permissions,
1057: $group,$file_name);
1.104 raeburn 1058: if ($totalprocessed) {
1059: if ($outcome eq 'ok') {
1060: my $updated_controls = $access_controls{$file_name};
1061: my ($showstart,$showend);
1062: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1063: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1064: $r->print('<th>'.&mt('Type of change').'</th><th>'.
1065: &mt('Access control').'</th><th>'.&mt('Dates available').
1066: '</th><th>'.&mt('Additional information').'</th>');
1.110 albertel 1067: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 1068: foreach my $chg (sort(keys(%processing))) {
1069: if (@{$processing{$chg}} > 0) {
1070: if ($chg eq 'delete') {
1071: if (!($deloutcome eq 'ok')) {
1.116 albertel 1072: $errors .='<span class="LC_error">'.
1073: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
1074: '</span>';
1.104 raeburn 1075: next;
1076: }
1077: }
1078: my $numchgs = @{$processing{$chg}};
1079: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1080: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
1081: '.</td>');
1.104 raeburn 1082: my $count = 0;
1.120 raeburn 1083: my %todisplay;
1.104 raeburn 1084: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
1.120 raeburn 1085: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.104 raeburn 1086: my $newkey = $key;
1087: if ($chg eq 'activate') {
1088: $newkey =~ s/^(\d+)/$$translation{$1}/;
1089: }
1.120 raeburn 1090: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
1.104 raeburn 1091: }
1.120 raeburn 1092: &build_access_summary($r,$count,$chg,%todisplay);
1.104 raeburn 1093: }
1094: }
1095: $r->print(&Apache::loncommon::end_data_table());
1096: } else {
1097: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
1.116 albertel 1098: $errors .= '<span class="LC_error">'.
1.179 albertel 1099: &mt('A problem occurred saving access control settings: [_1]',$outcome).
1.116 albertel 1100: '</span>';
1.104 raeburn 1101: }
1102: }
1103: if ($errors) {
1104: $r->print($errors);
1105: }
1106: }
1.108 raeburn 1107: my $allnew = 0;
1108: my $totalnew = 0;
1109: my $status = 'new';
1110: my ($firstitem,$lastitem);
1.221 raeburn 1111: my @types = ('course','domains','users');
1112: foreach my $newitem (@types) {
1.108 raeburn 1113: $allnew += $env{'form.new'.$newitem};
1114: }
1115: if ($allnew > 0) {
1116: my $now = time;
1117: my $then = $now + (60*60*24*180); # six months approx.
1.138 albertel 1118: &open_form($r,$url);
1.221 raeburn 1119: my %showtypes = &Apache::lonlocal::texthash (
1120: course => 'course/community',
1121: domains => 'domain',
1122: users => 'user',
1123: );
1124: foreach my $newitem (@types) {
1.108 raeburn 1125: if ($env{'form.new'.$newitem} > 0) {
1.221 raeburn 1126: $r->print('<br />'.&mt('Add new [_1]-based[_2] access control for portfolio file: [_3]','<b>'.$showtypes{$newitem},'</b>','<b>'.$env{'form.currentpath'}.$env{'form.selectfile'}.'</b>').'<br /><br />');
1.108 raeburn 1127: $firstitem = $totalnew;
1128: $lastitem = $totalnew + $env{'form.new'.$newitem};
1129: $totalnew = $lastitem;
1130: my @numbers;
1131: for (my $i=$firstitem; $i<$lastitem; $i++) {
1132: push (@numbers,$i);
1133: }
1134: &display_access_row($r,$status,$newitem,\@numbers,
1135: $access_controls{$file_name},$now,$then);
1136: }
1137: }
1.137 albertel 1138: &close_form($r,$url);
1.108 raeburn 1139: } else {
1.153 banghart 1140: my %anchor_fields = (
1141: 'currentpath' => $env{'form.currentpath'},
1142: 'access' => $env{'form.selectfile'}
1143: );
1144: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
1145: delete $anchor_fields{'access'};
1.188 bisitz 1146: $r->print(' '.&make_anchor($url,\%anchor_fields,&mt('Return to directory')));
1.108 raeburn 1147: }
1.104 raeburn 1148: return;
1149: }
1150:
1151: sub build_access_record {
1.108 raeburn 1152: my ($num,$scope,$start,$end,$chg) = @_;
1.109 albertel 1153: my $record = {
1154: type => $scope,
1155: time => {
1156: start => $start,
1157: end => $end
1158: },
1159: };
1160:
1161: if ($scope eq 'guest') {
1162: $record->{'password'} = $env{'form.password'};
1.170 raeburn 1163: } elsif ($scope eq 'course') {
1.109 albertel 1164: $record->{'domain'} = $env{'form.crsdom_'.$num};
1165: $record->{'number'} = $env{'form.crsnum_'.$num};
1.108 raeburn 1166: my @role_ids;
1.109 albertel 1167: my @delete_role_ids =
1168: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
1169: my @preserves =
1170: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
1171: if (@delete_role_ids) {
1172: foreach my $id (@preserves) {
1173: if (grep {$_ = $id} (@delete_role_ids)) {
1174: next;
1175: }
1176: push(@role_ids,$id);
1177: }
1178: } else {
1179: push(@role_ids,@preserves);
1180: }
1181:
1182: my $next_id = $env{'form.add_role_'.$num};
1183: if ($next_id) {
1184: push(@role_ids,$next_id);
1185: }
1186:
1.108 raeburn 1187: foreach my $id (@role_ids) {
1188: my (@roles,@accesses,@sections,@groups);
1189: if (($id == $next_id) && ($chg eq 'update')) {
1.109 albertel 1190: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1.108 raeburn 1191: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
1192: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1.109 albertel 1193: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1.108 raeburn 1194: } else {
1195: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
1196: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
1197: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
1198: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
1199: }
1.109 albertel 1200: $record->{'roles'}{$id}{'role'} = \@roles;
1201: $record->{'roles'}{$id}{'access'} = \@accesses;
1202: $record->{'roles'}{$id}{'section'} = \@sections;
1203: $record->{'roles'}{$id}{'group'} = \@groups;
1.108 raeburn 1204: }
1205: } elsif ($scope eq 'domains') {
1206: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1.109 albertel 1207: $record->{'dom'} = \@doms;
1.108 raeburn 1208: } elsif ($scope eq 'users') {
1209: my $userlist = $env{'form.users_'.$num};
1.109 albertel 1210: $userlist =~ s/\s+//sg;
1211: my %userhash = map { ($_,1) } (split(/,/,$userlist));
1212: foreach my $user (keys(%userhash)) {
1.108 raeburn 1213: my ($uname,$udom) = split(/:/,$user);
1.109 albertel 1214: push(@{$record->{'users'}}, {
1215: 'uname' => $uname,
1216: 'udom' => $udom
1217: });
1218: }
1.108 raeburn 1219: }
1.104 raeburn 1220: return $record;
1221: }
1222:
1223: sub get_dates_from_form {
1224: my ($id) = @_;
1225: my $startdate;
1226: my $enddate;
1227: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
1228: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
1229: if ( exists ($env{'form.noend_'.$id}) ) {
1230: $enddate = 0;
1231: }
1232: return ($startdate,$enddate);
1233: }
1234:
1.108 raeburn 1235: sub sort_users {
1.109 albertel 1236: my ($users) = @_;
1237: my @curr_users = map {
1238: $_->{'uname'}.':'.$_->{'udom'}
1239: } (@{$users});
1240: my $curr_user_list = join(",\n",sort(@curr_users));
1.108 raeburn 1241: return $curr_user_list;
1242: }
1243:
1.104 raeburn 1244: sub access_setting_table {
1.170 raeburn 1245: my ($r,$url,$filename,$access_controls,$action) = @_;
1.104 raeburn 1246: my ($public,$publictext);
1.170 raeburn 1247: $publictext ='Off';
1.104 raeburn 1248: my ($guest,$guesttext);
1.170 raeburn 1249: $guesttext = 'Off';
1.104 raeburn 1250: my @courses = ();
1251: my @domains = ();
1252: my @users = ();
1253: my $now = time;
1254: my $then = $now + (60*60*24*180); # six months approx.
1.108 raeburn 1255: my ($num,$scope,$publicnum,$guestnum);
1.170 raeburn 1256: my (%acl_count,%end,%start,%conditionals);
1.104 raeburn 1257: foreach my $key (sort(keys(%{$access_controls}))) {
1.108 raeburn 1258: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1.104 raeburn 1259: if ($scope eq 'public') {
1260: $public = $key;
1.108 raeburn 1261: $publicnum = $num;
1262: $publictext = &acl_status($start{$key},$end{$key},$now);
1263: } elsif ($scope eq 'guest') {
1264: $guest=$key;
1265: $guestnum = $num;
1266: $guesttext = &acl_status($start{$key},$end{$key},$now);
1.170 raeburn 1267: } else {
1268: $conditionals{$scope}{$key} = $$access_controls{$key};
1269: if ($scope eq 'course') {
1270: push(@courses,$key);
1271: } elsif ($scope eq 'domains') {
1272: push(@domains,$key);
1273: } elsif ($scope eq 'users') {
1274: push(@users,$key);
1275: }
1.104 raeburn 1276: }
1.108 raeburn 1277: $acl_count{$scope} ++;
1.104 raeburn 1278: }
1.108 raeburn 1279: $r->print('<table border="0"><tr><td valign="top">');
1.170 raeburn 1280: if ($action eq 'chgaccess') {
1281: &standard_settings($r,$now,$then,$url,$filename,\%acl_count,\%start,
1282: \%end,$public,$publicnum,$publictext,$guest,$guestnum,
1283: $guesttext,$access_controls,%conditionals);
1284: } else {
1285: &condition_setting($r,$access_controls,$now,$then,\%acl_count,
1286: \@domains,\@users,\@courses);
1287: }
1288: $r->print('</td></tr></table>');
1289: }
1290:
1291: sub standard_settings {
1292: my ($r,$now,$then,$url,$filename,$acl_count,$start,$end,$public,$publicnum,
1293: $publictext,$guest,$guestnum,$guesttext,$access_controls,%conditionals)=@_;
1.187 bisitz 1294: $r->print('<h3>'.&mt('Public access: [_1]',&mt($publictext)).'</h3>');
1.104 raeburn 1295: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1296: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1297: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1.110 albertel 1298: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 1299: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1300: if ($public) {
1301: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
1.170 raeburn 1302: &dateboxes($publicnum,$start->{$public},$end->{$public}).'</td>');
1.108 raeburn 1303: } else {
1304: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
1305: &dateboxes('0',$now,$then).'</td>');
1306: }
1307: $r->print(&Apache::loncommon::end_data_table_row());
1308: $r->print(&Apache::loncommon::end_data_table());
1309: $r->print('</td><td width="40"> </td><td valign="top">');
1.187 bisitz 1310: $r->print('<h3>'.&mt('Passphrase-protected access: [_1]',&mt($guesttext)).'</h3>');
1.104 raeburn 1311: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1312: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1313: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1.120 raeburn 1314: '</th><th>'. &mt('Passphrase').'</th>');
1.110 albertel 1315: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1316: $r->print(&Apache::loncommon::start_data_table_row());
1317: my $passwd;
1318: if ($guest) {
1.109 albertel 1319: $passwd = $$access_controls{$guest}{'password'};
1.108 raeburn 1320: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1.170 raeburn 1321: &dateboxes($guestnum,$start->{$guest},$end->{$guest}).'</td>');
1.108 raeburn 1322: } else {
1323: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1324: &dateboxes('1',$now,$then).'</td>');
1.104 raeburn 1325: }
1.108 raeburn 1326: $r->print('<td><input type="text" size="15" name="password" value="'.
1327: $passwd.'" /></td>');
1.104 raeburn 1328: $r->print(&Apache::loncommon::end_data_table_row());
1329: $r->print(&Apache::loncommon::end_data_table());
1.170 raeburn 1330: $r->print('</td></tr><tr><td colspan="3"> </td></tr>'.
1331: '<tr><td colspan="3">');
1332: my $numconditionals = 0;
1333: my $conditionstext;
1334: my %cond_status;
1335: foreach my $scope ('domains','users','course') {
1336: $numconditionals += $acl_count->{$scope};
1337: if ($acl_count->{$scope} > 0) {
1338: if ($conditionstext ne 'Active') {
1339: foreach my $key (keys(%{$conditionals{$scope}})) {
1340: $conditionstext = &acl_status($start->{$key},$end->{$key},$now);
1341: if ($conditionstext eq 'Active') {
1342: last;
1343: }
1344: }
1345: }
1346: }
1347: }
1348: if ($conditionstext eq '') {
1349: $conditionstext = 'Off';
1350: }
1351: my %anchor_fields = (
1352: 'access' => $env{'form.selectfile'},
1353: 'action' => 'chgconditions',
1354: 'currentpath' => $env{'form.currentpath'},
1355: );
1.187 bisitz 1356: $r->print('<h3>'.&mt('Conditional access: [_1]',&mt($conditionstext)).'</h3>');
1.170 raeburn 1357: if ($numconditionals > 0) {
1358: my $count = 1;
1359: my $chg = 'none';
1360: $r->print(&mt('You have previously set [_1] conditional access controls.',$numconditionals).' '.&make_anchor($url,\%anchor_fields,&mt('Change Conditions')).'<br /><br />');
1361: $r->print(&Apache::loncommon::start_data_table());
1362: $r->print(&Apache::loncommon::start_data_table_header_row());
1363: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
1364: '</th><th>'.&mt('Additional information').'</th>');
1365: $r->print(&Apache::loncommon::end_data_table_header_row());
1366: &build_access_summary($r,$count,$chg,%conditionals);
1367: $r->print(&Apache::loncommon::end_data_table());
1368: } else {
1.217 raeburn 1369: $r->print(&make_anchor($url,\%anchor_fields,&mt('Add conditional access')).' '.&mt('based on domain, username, or course/community affiliation.'));
1.170 raeburn 1370: }
1371: }
1372:
1373: sub condition_setting {
1374: my ($r,$access_controls,$now,$then,$acl_count,$domains,$users,$courses) = @_;
1375: $r->print('<tr><td valign="top">');
1376: &access_element($r,'domains',$acl_count,$domains,$access_controls,$now,$then);
1.158 albertel 1377: $r->print('</td><td> </td><td valign="top">');
1.170 raeburn 1378: &access_element($r,'users',$acl_count,$users,$access_controls,$now,$then);
1.158 albertel 1379: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
1.170 raeburn 1380: if ($acl_count->{course} > 0) {
1.158 albertel 1381: $r->print('<td colspan="3" valign="top">');
1382: } else {
1383: $r->print('<td valign="top">');
1384: }
1.170 raeburn 1385: &access_element($r,'course',$acl_count,$courses,$access_controls,$now,$then);
1.158 albertel 1386: $r->print('</td>');
1.108 raeburn 1387: $r->print('</td></tr></table>');
1388: }
1389:
1390: sub acl_status {
1391: my ($start,$end,$now) = @_;
1392: if ($start > $now) {
1.170 raeburn 1393: return 'Inactive';
1.108 raeburn 1394: }
1395: if ($end && $end<$now) {
1.170 raeburn 1396: return 'Inactive';
1.108 raeburn 1397: }
1.170 raeburn 1398: return 'Active';
1.108 raeburn 1399: }
1400:
1401: sub access_element {
1402: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1.221 raeburn 1403: my %typetext = &Apache::lonlocal::texthash(
1404: domains => 'Domain',
1405: users => 'User',
1406: course => 'Course/Community'
1407: );
1.222 ! raeburn 1408: $r->print('<h3>'.&mt('[_1]-based conditional access: ',$typetext{$type}));
1.108 raeburn 1409: if ($$acl_count{$type}) {
1410: $r->print($$acl_count{$type}.' ');
1411: if ($$acl_count{$type} > 1) {
1412: $r->print(&mt('conditions'));
1413: } else {
1414: $r->print(&mt('condition'));
1415: }
1416: } else {
1417: $r->print(&mt('Off'));
1418: }
1419: $r->print('</h3>');
1420: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1421: return;
1422: }
1423:
1424: sub display_access_row {
1425: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1.221 raeburn 1426: my $showtype;
1427: if ($type eq 'course') {
1428: $showtype = &mt('Courses/Communities');
1429: } elsif ($type eq 'domains') {
1430: $showtype = &mt('Domains');
1431: } elsif ($type eq 'users') {
1432: $showtype = &mt('Users');
1433: }
1.108 raeburn 1434: if (@{$items} > 0) {
1435: my @all_doms;
1436: my $colspan = 3;
1437: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1438: $r->print(&Apache::loncommon::start_data_table_header_row());
1.221 raeburn 1439: $r->print('<th>'.&mt('Action?').'</th><th>'.$showtype.'</th><th>'.
1.108 raeburn 1440: &mt('Dates available').'</th>');
1.172 raeburn 1441: if ($type eq 'course' && $status eq 'old') {
1.221 raeburn 1442:
1443: $r->print('<th>'.&mt('Allowed course/community affiliations').
1.108 raeburn 1444: '</th>');
1445: $colspan ++;
1446: } elsif ($type eq 'domains') {
1.178 albertel 1447: @all_doms = sort(&Apache::lonnet::all_domains());
1.108 raeburn 1448: }
1.110 albertel 1449: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1450: foreach my $key (@{$items}) {
1.118 albertel 1451: $r->print(&Apache::loncommon::start_data_table_row());
1.170 raeburn 1452: if ($type eq 'course') {
1.118 albertel 1453: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1.108 raeburn 1454: } elsif ($type eq 'domains') {
1455: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1456: $then);
1457: } elsif ($type eq 'users') {
1458: &users_row($r,$status,$key,$access_controls,$now,$then);
1459: }
1.118 albertel 1460: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1461: }
1462: if ($status eq 'old') {
1.111 albertel 1463: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1464: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1465: '</td>');
1.111 albertel 1466: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1467: }
1468: $r->print(&Apache::loncommon::end_data_table());
1469: } else {
1.221 raeburn 1470: $r->print(&mt('No [_1]-based conditions defined.',$showtype).'<br />'.
1471: &additional_item($type));
1.108 raeburn 1472: }
1473: return;
1474: }
1475:
1.110 albertel 1476: sub course_js {
1477: return qq|
1.108 raeburn 1478: <script type="text/javascript">
1.172 raeburn 1479: function setRoleOptions(num,roleid,cdom,cnum,type) {
1480: updateIndexNum = getIndexByValue('update',num);
1481: var addItem = 'add_role_'+num;
1482: var addIndexNum = getIndexByName(addItem);
1483: if (document.portform.elements[addItem].checked) {
1484: document.portform.elements[updateIndexNum].checked = true;
1485: var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1.108 raeburn 1486: var title = 'Roles_Chooser';
1487: var options = 'scrollbars=1,resizable=1,menubar=0';
1488: options += ',width=700,height=600';
1489: rolebrowser = open(url,title,options,'1');
1490: rolebrowser.focus();
1491: } else {
1.172 raeburn 1492: addArray = new Array ('role','access','section','group');
1493: for (var j=0;j<addArray.length;j++) {
1494: var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid);
1495: document.portform.elements[itemIndex].value = '';
1.108 raeburn 1496: }
1497: }
1498: }
1499:
1.172 raeburn 1500: function getIndexByName(item) {
1.108 raeburn 1501: for (var i=0;i<document.portform.elements.length;i++) {
1.172 raeburn 1502: if (document.portform.elements[i].name == item) {
1.108 raeburn 1503: return i;
1504: }
1505: }
1506: return -1;
1507: }
1508:
1.172 raeburn 1509: function getIndexByValue(name,value) {
1.108 raeburn 1510: for (var i=0;i<document.portform.elements.length;i++) {
1511: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1512: return i;
1513: }
1514: }
1515: return -1;
1516: }
1517:
1518: </script>
1.110 albertel 1519: |;
1520: }
1521:
1522: sub course_row {
1.118 albertel 1523: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1.115 raeburn 1524: my $content;
1.110 albertel 1525: my $defdom = $env{'user.domain'};
1526: if ($status eq 'old') {
1.115 raeburn 1527: $content = $$access_controls{$item};
1528: $defdom = $content->{'domain'};
1.110 albertel 1529: }
1530: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1531: .&course_js();
1.221 raeburn 1532: my $showtype = &mt('Course/Community');
1533: my $crstype = 'Course';
1.108 raeburn 1534: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1535: $type);
1.110 albertel 1536: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1.108 raeburn 1537: if ($status eq 'old') {
1.115 raeburn 1538: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 1539: my %course_description = &Apache::lonnet::coursedescription($cid);
1.221 raeburn 1540: if ($course_description{'type'} ne '') {
1541: $crstype = $course_description{'type'};
1542: }
1.115 raeburn 1543: $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 1544: } elsif ($status eq 'new') {
1.221 raeburn 1545: $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 1546: }
1.172 raeburn 1547: $r->print('<td>'.&dateboxes($num,$start,$end));
1548: my $newrole_id = 1;
1.108 raeburn 1549: if ($status eq 'old') {
1.172 raeburn 1550: $r->print('</td><td>');
1.108 raeburn 1551: my $max_id = 0;
1.172 raeburn 1552: if (keys(%{$content->{'roles'}}) > 0) {
1553: $r->print('<table><tr><th>'.&mt('Action').'</th>'.
1554: '<th>'.&mt('Roles').'</th>'.
1555: '<th>'.&mt('Access').'</th>'.
1556: '<th>'.&mt('Sections').'</th>'.
1557: '<th>'.&mt('Groups').'</th></tr>');
1558: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1559: if ($role_id > $max_id) {
1560: $max_id = $role_id;
1561: }
1562: $max_id ++;
1.221 raeburn 1563: my $role_selects = &role_selectors($num,$role_id,$crstype,$content,'display');
1.200 bisitz 1564: $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 1565: }
1566: $r->print('</table>');
1567: }
1568: $r->print('<br />'.&mt('Add a roles-based condition').
1.214 bisitz 1569: ' <input type="checkbox" name="add_role_'.
1.172 raeburn 1570: $num.'" onClick="javascript:setRoleOptions('."'$num',
1571: '$max_id','$content->{'domain'}','$content->{'number'}',
1.221 raeburn 1572: '$showtype'".')" value="" />');
1.172 raeburn 1573: $newrole_id = $max_id;
1574: } else {
1.214 bisitz 1575: $r->print('<input type="hidden" name="add_role_'.$num.'" value="" />');
1.108 raeburn 1576: }
1.172 raeburn 1577: $r->print(&add_course_role($num,$newrole_id));
1578: $r->print('</td>');
1.108 raeburn 1579: return;
1580: }
1581:
1.172 raeburn 1582: sub add_course_role {
1583: my ($num,$max_id) = @_;
1584: my $output;
1585: $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'.
1586: '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'.
1587: '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'.
1588: '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />';
1589: return $output;
1590: }
1591:
1.108 raeburn 1592: sub domains_row {
1593: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1594: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1595: 'domains');
1.207 bisitz 1596: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="multiple">'.
1.108 raeburn 1597: ' <option value="">'.&mt('Please select').'</option>';
1598: if ($status eq 'old') {
1.109 albertel 1599: my $content = $$access_controls{$item};
1600: foreach my $dom (@{$all_doms}) {
1601: if ((@{$content->{'dom'}} > 0)
1602: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.214 bisitz 1603: $dom_select .= '<option value="'.$dom.'" selected="selected">'.
1.108 raeburn 1604: $dom.'</option>';
1605: } else {
1606: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1607: }
1608: }
1609: } else {
1610: foreach my $dom (@{$all_doms}) {
1611: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1612: }
1613: }
1.112 albertel 1614: $dom_select .= '</select>';
1.108 raeburn 1615: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1616: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1617: }
1618:
1619: sub users_row {
1620: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1621: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1622: 'users');
1623: my $curr_user_list;
1624: if ($status eq 'old') {
1.109 albertel 1625: my $content = $$access_controls{$item};
1626: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1627: }
1628: $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>');
1629: }
1630:
1631: sub additional_item {
1632: my ($type) = @_;
1.221 raeburn 1633: my $showtype;
1634: if ($type eq 'course') {
1635: $showtype = &mt('course/community');
1636: } elsif ($type eq 'domains') {
1637: $showtype = &mt('domains');
1638: } elsif ($type eq 'users') {
1639: $showtype = &mt('users');
1640: }
1641: my $output = &mt('Add new [_1] condition(s)?',$showtype).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1.108 raeburn 1642: return $output;
1643: }
1644:
1645: sub actionbox {
1646: my ($status,$num,$scope) = @_;
1.200 bisitz 1647: my $output = '<span class="LC_nobreak"><label>';
1.108 raeburn 1648: if ($status eq 'new') {
1.170 raeburn 1649: my $checkstate;
1650: if ($scope eq 'domains' || $scope eq 'users' || $scope eq 'course') {
1651: $checkstate = 'checked="checked"';
1652: }
1653: $output .= '<input type="checkbox" name="activate" value="'.$num.'" '.
1654: $checkstate.' />'.
1.108 raeburn 1655: &mt('Activate');
1656: } else {
1657: $output .= '<input type="checkbox" name="delete" value="'.$num.
1.200 bisitz 1658: '" />'.&mt('Delete').'</label></span><br /><span class="LC_nobreak">'.
1.108 raeburn 1659: '<label><input type="checkbox" name="update" value="'.
1660: $num.'" />'.&mt('Update');
1661: }
1.112 albertel 1662: $output .= '</label></span><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1.108 raeburn 1663: return $output;
1664: }
1665:
1666: sub dateboxes {
1667: my ($num,$start,$end) = @_;
1668: my $noend;
1669: if ($end == 0) {
1670: $noend = 'checked="checked"';
1671: }
1672: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1673: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1674: undef,undef,1);
1675: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1676: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1.200 bisitz 1677: undef,undef,1). ' <span class="LC_nobreak"><label>'.
1.108 raeburn 1678: '<input type="checkbox" name="noend_'.
1679: $num.'" '.$noend.' />'.&mt('No end date').
1.112 albertel 1680: '</label></span>';
1.108 raeburn 1681:
1682: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1683: return $output;
1684: }
1685:
1686: sub unpack_acc_key {
1687: my ($acc_key) = @_;
1688: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1689: return ($num,$scope,$end,$start);
1690: }
1691:
1692: sub set_identifiers {
1693: my ($status,$item,$now,$then,$scope) = @_;
1694: if ($status eq 'old') {
1695: return(&unpack_acc_key($item));
1696: } else {
1697: return($item,$scope,$then,$now);
1698: }
1699: }
1700:
1701: sub role_selectors {
1.172 raeburn 1702: my ($num,$role_id,$type,$content,$caller) = @_;
1.108 raeburn 1703: my ($output,$cdom,$cnum,$longid);
1704: if ($caller eq 'display') {
1705: $longid = '_'.$num.'_'.$role_id;
1.172 raeburn 1706: $cdom = $$content{'domain'};
1707: $cnum = $$content{'number'};
1.108 raeburn 1708: } elsif ($caller eq 'rolepicker') {
1709: $cdom = $env{'form.cdom'};
1710: $cnum = $env{'form.cnum'};
1711: }
1.221 raeburn 1712: my $crstype = 'Course';
1713: if ($cnum =~ /^$match_community$/) {
1714: $crstype = 'Community'
1715: }
1.108 raeburn 1716: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1.221 raeburn 1717: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$crstype);
1.108 raeburn 1718: if (!@{$sections}) {
1719: @{$sections} = ('none');
1720: } else {
1721: unshift(@{$sections},('all','none'));
1722: }
1723: if (!@{$groups}) {
1724: @{$groups} = ('none');
1725: } else {
1726: unshift(@{$groups},('all','none'));
1727: }
1728: my @allacesses = sort(keys(%{$accesshash}));
1729: my (%sectionhash,%grouphash);
1730: foreach my $sec (@{$sections}) {
1731: $sectionhash{$sec} = $sec;
1732: }
1733: foreach my $grp (@{$groups}) {
1734: $grouphash{$grp} = $grp;
1735: }
1736: my %lookup = (
1737: 'role' => $rolehash,
1738: 'access' => $accesshash,
1739: 'section' => \%sectionhash,
1740: 'group' => \%grouphash,
1741: );
1742: my @allaccesses = sort(keys(%{$accesshash}));
1743: my %allitems = (
1744: 'role' => $allroles,
1745: 'access' => \@allaccesses,
1746: 'section' => $sections,
1.172 raeburn 1747: 'group' => $groups,
1.108 raeburn 1748: );
1749: foreach my $item ('role','access','section','group') {
1.207 bisitz 1750: $output .= '<td><select name="'.$item.$longid.'" multiple="multiple" size="4">'."\n";
1.108 raeburn 1751: foreach my $entry (@{$allitems{$item}}) {
1752: if ($caller eq 'display') {
1753: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1754: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1.214 bisitz 1755: $output .= ' <option value="'.$entry.'" selected="selected">'.
1.108 raeburn 1756: $lookup{$item}{$entry}.'</option>';
1757: next;
1758: }
1759: }
1760: $output .= ' <option value="'.$entry.'">'.
1761: $lookup{$item}{$entry}.'</option>';
1762: }
1763: $output .= '</select>';
1764: }
1765: $output .= '</td>';
1766: return $output;
1767: }
1768:
1769: sub role_options_window {
1770: my ($r) = @_;
1771: my $type = $env{'form.type'};
1.172 raeburn 1772: my $rolenum = $env{'form.setroles'};
1773: my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/);
1774: my $role_elements;
1775: foreach my $item ('role','access','section','group') {
1776: $role_elements .= "'".$item.'_'.$rolenum."',";
1777: }
1778: $role_elements =~ s/,$//;
1779: my $role_selects = &role_selectors($num,$role_id,$type,undef,
1780: 'rolepicker');
1.108 raeburn 1781: $r->print(<<"END_SCRIPT");
1782: <script type="text/javascript">
1783: function setRoles() {
1.172 raeburn 1784: var role_elements = new Array($role_elements);
1785: for (var i=0; i<role_elements.length; i++) {
1.108 raeburn 1786: var copylist = '';
1787: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1788: if (document.rolepicker.elements[i].options[j].selected) {
1789: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1790: }
1791: }
1792: copylist = copylist.substr(0,copylist.length-1);
1.172 raeburn 1793: var openerItem = getIndexByName(role_elements[i]);
1794: opener.document.portform.elements[openerItem].value = copylist;
1.108 raeburn 1795: }
1.172 raeburn 1796: var roleAdder = getIndexByName('add_role_$num');
1797: opener.document.portform.elements[roleAdder].value = '$role_id';
1.108 raeburn 1798: self.close();
1799: }
1.172 raeburn 1800:
1801: function getIndexByName(item) {
1802: for (var i=0;i<opener.document.portform.elements.length;i++) {
1803: if (opener.document.portform.elements[i].name == item) {
1804: return i;
1805: }
1806: }
1807: return -1;
1808: }
1809:
1.108 raeburn 1810: </script>
1811: END_SCRIPT
1.220 bisitz 1812: $r->print(
1813: '<p>'
1814: .&mt('Select roles, '.lc($type).' status, section(s) and group(s) for users'
1815: .' who will be able to access the portfolio file.')
1816: .'</p>'
1817: );
1818: $r->print(
1819: '<form name="rolepicker" action="/adm/portfolio" method="post">'
1820: .'<table><tr>'
1821: .'<th>'.&mt('Roles').'</th>'
1822: .'<th>'.&mt("$type status").'</th>'
1823: .'<th>'.&mt('Sections').'</th>'
1824: .'<th>'.&mt('Groups').'</th>'
1825: .'</tr><tr>'.$role_selects.'</tr>'
1826: .'</table><br />'
1827: .'<input type="button" name="rolepickbutton" value="'.&mt('Save').'" onclick="setRoles()" />'
1828: );
1.108 raeburn 1829: return;
1.104 raeburn 1830: }
1831:
1.47 banghart 1832: sub select_files {
1.138 albertel 1833: my ($r) = @_;
1.82 albertel 1834: if ($env{'form.continue'} eq 'true') {
1.60 banghart 1835: # here we update the selections for the currentpath
1836: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 1837: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1838: if (scalar(@items)){
1.85 banghart 1839: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 1840: }
1.62 banghart 1841: } else {
1842: #empty the file for a fresh start
1.83 banghart 1843: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 1844: }
1.82 albertel 1845: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 1846: my $java_files = join ",", @files;
1847: if ($java_files) {
1848: $java_files.=',';
1.60 banghart 1849: }
1.63 banghart 1850: my $javascript =(<<ENDSMP);
1.113 albertel 1851: <script type="text/javascript">
1.48 banghart 1852: function finishSelect() {
1.62 banghart 1853: ENDSMP
1.63 banghart 1854: $javascript .= 'fileList = "'.$java_files.'";';
1855: $javascript .= (<<ENDSMP);
1.49 banghart 1856: for (i=0;i<document.forms.checkselect.length;i++) {
1857: if (document.forms.checkselect[i].checked){
1.54 banghart 1858: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 1859: }
1860: }
1.186 albertel 1861: var hwfield = opener.document.getElementsByName('$env{'form.fieldname'}');
1862: hwfield[0].value = fileList;
1.48 banghart 1863: self.close();
1864: }
1865: </script>
1866: ENDSMP
1.63 banghart 1867: $r->print($javascript);
1.198 bisitz 1868: $r->print("<h1>".&mt('Select portfolio files')."</h1>");
1.88 albertel 1869: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1870: if (@otherfiles) {
1.198 bisitz 1871: $r->print(&Apache::loncommon::start_data_table()
1872: .&Apache::loncommon::start_data_table_header_row()
1873: .'<th>'.&mt('Files selected from other directories:')."</th>"
1874: .&Apache::loncommon::end_data_table_header_row()
1875: );
1.88 albertel 1876: foreach my $file (@otherfiles) {
1.198 bisitz 1877: $r->print(&Apache::loncommon::start_data_table_row()
1878: .'<td>'.$file."</td>"
1879: .&Apache::loncommon::end_data_table_row()
1880: );
1.88 albertel 1881: }
1.198 bisitz 1882: $r->print(&Apache::loncommon::end_data_table()
1883: .'<br />'
1884: );
1.60 banghart 1885: }
1.198 bisitz 1886: $r->print('<div>'
1887: .&mt('Check as many files as you wish in response to the problem:')
1888: .'</div>'
1889: );
1.47 banghart 1890: }
1.138 albertel 1891:
1.176 albertel 1892:
1893: sub check_for_upload {
1894: my ($path,$fname,$group,$element) = @_;
1.174 raeburn 1895: my $disk_quota = &get_quota($group);
1.176 albertel 1896: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
1897: my $portfolio_root = &get_portfolio_root();
1898: my $port_path = &get_port_path();
1.191 raeburn 1899: my ($uname,$udom) = &get_name_dom($group);
1.38 banghart 1900: # Fixme --- Move the checking for existing file to LOND error return
1.191 raeburn 1901: my @dir_list=&get_dir_list($portfolio_root,$path,$group);
1.34 banghart 1902: my $found_file = 0;
1.76 banghart 1903: my $locked_file = 0;
1.33 banghart 1904: foreach my $line (@dir_list) {
1.76 banghart 1905: my ($file_name)=split(/\&/,$line,2);
1906: if ($file_name eq $fname){
1.176 albertel 1907: $file_name = $path.$file_name;
1.138 albertel 1908: $file_name = &prepend_group($file_name);
1.33 banghart 1909: $found_file = 1;
1.102 raeburn 1910: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.76 banghart 1911: $locked_file = 1;
1912: }
1.33 banghart 1913: }
1914: }
1.191 raeburn 1915: my $getpropath = 1;
1916: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
1.176 albertel 1917:
1.87 albertel 1918: if (($current_disk_usage + $filesize) > $disk_quota){
1.185 banghart 1919: my $msg = '<span class="LC_error">'.
1920: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
1921: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
1.176 albertel 1922: return ('will_exceed_quota',$msg);
1923: } elsif ($found_file) {
1924: if ($locked_file) {
1.185 banghart 1925: my $msg = '<span class="LC_error">';
1.188 bisitz 1926: $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
1.185 banghart 1927: $msg .= '</span><br />';
1928: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
1.176 albertel 1929: return ('file_locked',$msg);
1930: } else {
1.185 banghart 1931: my $msg = '<span class="LC_error">';
1932: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1933: $msg .= '</span>';
1934: $msg .= '<br />';
1935: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
1.176 albertel 1936: return ('file_exists',$msg);
1937: }
1938: }
1939: }
1940:
1941: sub upload {
1942: my ($r,$url,$group)=@_;
1943: my $fname=&Apache::lonnet::clean_filename($env{'form.uploaddoc.filename'});
1.195 raeburn 1944: my $disk_quota = &get_quota($group);
1945: my $portfolio_root = &get_portfolio_root();
1946: my $port_path = &get_port_path();
1947: my ($uname,$udom) = &get_name_dom($group);
1948: my $getpropath = 1;
1949: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
1950: my ($state,$msg) =
1951: &Apache::loncommon::check_for_upload($env{'form.currentpath'},$fname,
1952: $group,'uploaddoc',$portfolio_root,
1953: $port_path,$disk_quota,
1954: $current_disk_usage,$uname,$udom);
1.176 albertel 1955: if ($state eq 'will_exceed_quota'
1956: || $state eq 'file_locked'
1957: || $state eq 'file_exists' ) {
1958: $r->print($msg.&done('Back',$url));
1959: return;
1960: }
1961:
1962: my (%allfiles,%codebase,$mode);
1963: if ($env{'form.uploaddoc.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
1.193 raeburn 1964: if ($env{'form.parserflag'}) {
1965: $mode = 'parse';
1966: }
1.176 albertel 1967: }
1968: my $result=
1969: &Apache::lonnet::userfileupload('uploaddoc','',
1970: $port_path.$env{'form.currentpath'},
1971: $mode,\%allfiles,\%codebase);
1972: if ($result !~ m|^/uploaded/|) {
1.188 bisitz 1973: $r->print('<span class="LC_error">'.&mt('An error occurred ([_1]) while trying to upload [_2].'
1974: ,$result,&display_file()).'</span><br />');
1.176 albertel 1975: $r->print(&done('Back',$url));
1976: } else {
1977: if (%allfiles) {
1.195 raeburn 1978: if (!&suppress_embed_prompt()) {
1979: my $state = <<STATE;
1.176 albertel 1980: <input type="hidden" name="action" value="upload_embedded" />
1981: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
1982: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
1983: <input type="hidden" name="mode" value="$env{'form.mode'}" />
1984: STATE
1.195 raeburn 1985: $r->print("<h2>".&mt("Reference Warning")."</h2>");
1986: $r->print("<p>".&mt("Completed upload of the file. This file contained references to other files. You must upload the referenced files or else the uploaded file may not work properly.")."</p>");
1987: $r->print("<p>".&mt("Please select the locations from which the referenced files are to be uploaded.")."</p>");
1988: $r->print(&Apache::loncommon::ask_for_embedded_content('/adm/portfolio',$state,\%allfiles,\%codebase,
1.180 albertel 1989: {'error_on_invalid_names' => 1,
1990: 'ignore_remote_references' => 1,}));
1.195 raeburn 1991: $r->print('<p>Or '.&done('Return to directory',$url).'</p>');
1992: }
1.176 albertel 1993: } else {
1994: $r->print(&done(undef,$url));
1995: }
1996: }
1997: }
1998:
1.80 banghart 1999: sub lock_info {
1.137 albertel 2000: my ($r,$url,$group) = @_;
1.191 raeburn 2001: my ($uname,$udom) = &get_name_dom($group);
1.102 raeburn 2002: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
2003: $uname);
1.84 banghart 2004: my $file_name = $env{'form.lockinfo'};
1.138 albertel 2005: $file_name = &prepend_group($file_name);
1.102 raeburn 2006: if (defined($file_name) && defined($$current_permissions{$file_name})) {
2007: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1.156 albertel 2008: next if (ref($array_item) ne 'ARRAY');
2009:
2010: my $filetext;
2011: if (defined($group)) {
2012: $filetext = '<strong>'.$env{'form.lockinfo'}.
2013: '</strong> (group: '.$group.')';
2014: } else {
2015: $filetext = '<strong>'.$file_name.'</strong>';
2016: }
2017:
2018: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
2019: '</strong><br />';
2020: if ($$array_item[-1] eq 'graded') {
2021: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
2022: $filetext,$title));
2023: } elsif ($$array_item[-1] eq 'handback') {
2024: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
2025: $filetext,$title));
2026: } else {
2027: # submission style lock
2028: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
2029: $filetext,$title));
2030: }
2031: my %course_description =
2032: &Apache::lonnet::coursedescription($$array_item[1]);
2033: if ( $course_description{'description'} ne '') {
1.188 bisitz 2034: $r->print(&mt('In the course:').' <strong>'.$course_description{'description'}.'</strong><br />');
1.156 albertel 2035: }
1.102 raeburn 2036: }
1.84 banghart 2037: }
1.185 banghart 2038: $r->print(&done(&mt('Back'),$url));
1.80 banghart 2039: return 'ok';
2040: }
1.138 albertel 2041:
1.25 albertel 2042: sub createdir {
1.191 raeburn 2043: my ($r,$url,$group)=@_;
1.82 albertel 2044: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 2045: if ($newdir eq '') {
1.116 albertel 2046: $r->print('<span class="LC_error">'.
1.37 banghart 2047: &mt("Error: no directory name was provided.").
1.116 albertel 2048: '</span><br />');
1.138 albertel 2049: $r->print(&done(undef,$url));
1.37 banghart 2050: return;
1.94 raeburn 2051: }
1.138 albertel 2052: my $portfolio_root = &get_portfolio_root();
1.191 raeburn 2053: my @dir_list=&get_dir_list($portfolio_root,undef,$group);
1.37 banghart 2054: my $found_file = 0;
2055: foreach my $line (@dir_list) {
2056: my ($filename)=split(/\&/,$line,2);
2057: if ($filename eq $newdir){
2058: $found_file = 1;
2059: }
2060: }
2061: if ($found_file){
1.188 bisitz 2062: $r->print('<span class="LC_error">'
2063: .&mt('Unable to create a directory named [_1].','<strong>'.$newdir.'</strong>')
2064: .' '.&mt('A file or directory by that name already exists.').'</span><br />');
1.37 banghart 2065: } else {
1.191 raeburn 2066: my ($uname,$udom) = &get_name_dom($group);
1.138 albertel 2067: my $port_path = &get_port_path();
1.94 raeburn 2068: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
2069: $port_path.$env{'form.currentpath'}.$newdir);
1.37 banghart 2070: if ($result ne 'ok') {
1.188 bisitz 2071: $r->print('<span class="LC_error">'
2072: .&mt('An error occurred ([_1]) while trying to create a new directory [_2].'
2073: ,$result,&display_file())
2074: .'</span><br />');
1.37 banghart 2075: }
1.24 albertel 2076: }
1.82 albertel 2077: if ($newdir ne $env{'form.newdir'}) {
1.188 bisitz 2078: $r->print(&mt('The new directory name was changed from [_1] to [_2].'
2079: ,'<strong>'.$env{'form.newdir'}.'</strong>','<strong>'.$newdir.'</strong>'));
1.67 banghart 2080: }
1.137 albertel 2081: $r->print(&done(undef,$url));
1.94 raeburn 2082: }
2083:
2084: sub get_portfolio_root {
1.163 raeburn 2085: my ($udom,$uname,$group) = @_;
1.160 raeburn 2086: if (!(defined($udom)) || !(defined($uname))) {
1.191 raeburn 2087: ($uname,$udom) = &get_name_dom($group);
1.160 raeburn 2088: }
1.163 raeburn 2089: my $path = '/userfiles/portfolio';
2090: if (!defined($group)) {
2091: if (defined($env{'form.group'})) {
2092: $group = $env{'form.group'};
2093: }
1.94 raeburn 2094: }
1.163 raeburn 2095: if (defined($group)) {
2096: $path = '/userfiles/groups/'.$group.'/portfolio';
2097: }
1.191 raeburn 2098: return $path;
1.94 raeburn 2099: }
2100:
1.126 raeburn 2101: sub get_group_quota {
2102: my ($group) = @_;
2103: my $group_quota;
2104: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2105: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2106: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2107: if (%curr_groups) {
2108: my %group_info = &Apache::longroup::get_group_settings(
2109: $curr_groups{$group});
2110: $group_quota = $group_info{'quota'}; #expressed in Mb
2111: if ($group_quota) {
2112: $group_quota = 1000 * $group_quota; #expressed in k
1.191 raeburn 2113: }
1.126 raeburn 2114: }
2115: return $group_quota;
1.191 raeburn 2116: }
1.126 raeburn 2117:
1.94 raeburn 2118: sub get_dir_list {
1.191 raeburn 2119: my ($portfolio_root,$path,$group) = @_;
1.176 albertel 2120: $path ||= $env{'form.currentpath'};
1.191 raeburn 2121: my ($uname,$udom) = &get_name_dom($group);
2122: my $getpropath = 1;
2123: return &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.94 raeburn 2124: }
2125:
2126: sub get_name_dom {
1.191 raeburn 2127: my ($group) = @_;
1.94 raeburn 2128: my ($uname,$udom);
1.191 raeburn 2129: if (defined($group)) {
1.94 raeburn 2130: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2131: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
2132: } else {
2133: $udom = $env{'user.domain'};
2134: $uname = $env{'user.name'};
2135: }
2136: return ($uname,$udom);
2137: }
2138:
1.102 raeburn 2139: sub prepend_group {
1.138 albertel 2140: my ($filename) = @_;
2141: if (defined($env{'form.group'})) {
2142: $filename = $env{'form.group'}.$filename;
1.102 raeburn 2143: }
2144: return $filename;
2145: }
2146:
1.94 raeburn 2147: sub get_namespace {
2148: my $namespace = 'portfolio';
1.138 albertel 2149: if (defined($env{'form.group'})) {
1.191 raeburn 2150: my ($uname,$udom) = &get_name_dom($env{'form.group'});
1.138 albertel 2151: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
1.94 raeburn 2152: }
2153: return $namespace;
2154: }
2155:
2156: sub get_port_path {
2157: my $port_path;
1.138 albertel 2158: if (defined($env{'form.group'})) {
2159: $port_path = "groups/$env{'form.group'}/portfolio";
1.94 raeburn 2160: } else {
2161: $port_path = 'portfolio';
2162: }
2163: return $port_path;
1.24 albertel 2164: }
2165:
1.120 raeburn 2166: sub missing_priv {
1.138 albertel 2167: my ($r,$url,$priv) = @_;
1.120 raeburn 2168: my $longtext = {
2169: upload => 'upload files',
2170: delete => 'delete files',
2171: rename => 'rename files',
2172: setacl => 'set access controls for files',
2173: };
2174: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
2175: my $rtnlink = '<a href="'.$url;
2176: if ($url =~ /\?/) {
2177: $rtnlink .= '&';
2178: } else {
2179: $rtnlink .= '?';
2180: }
2181: $rtnlink .= 'currentpath='.$escpath;
1.188 bisitz 2182: $r->print('<h3>'.&mt('Action disallowed').'</h3>');
1.120 raeburn 2183: $r->print(&mt('You do not have sufficient privileges to [_1] ',
2184: $longtext->{$priv}));
1.138 albertel 2185: if (defined($env{'form.group'})) {
1.212 weissno 2186: $r->print(&mt("in the group's group portfolio."));
1.137 albertel 2187: $rtnlink .= &group_args()
1.120 raeburn 2188: } else {
2189: $r->print(&mt('in this portfolio.'));
2190: }
1.188 bisitz 2191: $rtnlink .= '">'.&mt('Return to directory').'</a>';
1.120 raeburn 2192: $r->print('<br />'.$rtnlink);
2193: $r->print(&Apache::loncommon::end_page());
2194: return;
2195: }
2196:
1.132 raeburn 2197: sub coursegrp_portfolio_header {
1.137 albertel 2198: my ($cdom,$cnum,$grp_desc)=@_;
1.132 raeburn 2199: my $gpterm = &Apache::loncommon::group_term();
2200: my $ucgpterm = $gpterm;
2201: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.137 albertel 2202: if ($env{'form.ref'}) {
1.136 raeburn 2203: &Apache::lonhtmlcommon::add_breadcrumb
2204: ({href=>"/adm/coursegroups",
2205: text=>"Groups",
2206: title=>"Course Groups"});
2207: }
1.132 raeburn 2208: &Apache::lonhtmlcommon::add_breadcrumb
1.138 albertel 2209: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
1.132 raeburn 2210: text=>"$ucgpterm: $grp_desc",
2211: title=>"Go to group's home page"},
1.137 albertel 2212: {href=>"/adm/coursegrp_portfolio?".&group_args(),
1.132 raeburn 2213: text=>"Group Portfolio",
1.136 raeburn 2214: title=>"Display group portfolio"});
1.132 raeburn 2215: my $output = &Apache::lonhtmlcommon::breadcrumbs(
2216: &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
2217: return $output;
2218: }
2219:
1.174 raeburn 2220: sub get_quota {
2221: my ($group) = @_;
2222: my $disk_quota;
2223: if (defined($group)) {
2224: my $grp_quota = &get_group_quota($group); # quota expressed in k
2225: if ($grp_quota ne '') {
2226: $disk_quota = $grp_quota;
2227: } else {
2228: $disk_quota = 0;
2229: }
2230: } else {
2231: $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
2232: $env{'user.domain'}); #expressed in Mb
2233: $disk_quota = 1000 * $disk_quota; # convert from Mb to kb
2234: }
2235: return $disk_quota;
2236: }
2237:
1.195 raeburn 2238: sub suppress_embed_prompt {
2239: my $suppress_prompt = 0;
2240: if (($env{'request.role'} =~ /^st/) && ($env{'request.course.id'} ne '')) {
2241: if ($env{'course.'.$env{'request.course.id'}.'.suppress_embed_prompt'} eq 'yes') {
2242: $suppress_prompt = 1;
2243: }
2244: }
2245: return $suppress_prompt;
2246: }
2247:
2248:
1.24 albertel 2249: sub handler {
2250: # this handles file management
2251: my $r = shift;
1.73 banghart 2252: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.108 raeburn 2253: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
2254: 'fieldname','mode','rename','continue','group','access','setnum',
1.136 raeburn 2255: 'cnum','cdom','type','setroles','showversions','ref']);
1.138 albertel 2256: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
1.94 raeburn 2257: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
2258: $url = $1.$2;
2259: $caller = $2;
2260: }
1.137 albertel 2261: my ($can_modify,$can_delete,$can_upload,$can_setacl);
1.94 raeburn 2262: if ($caller eq 'coursegrp_portfolio') {
2263: # Needs to be in a course
2264: if (! ($env{'request.course.fn'})) {
2265: # Not in a course
2266: $env{'user.error.msg'}=
2267: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
2268: return HTTP_NOT_ACCEPTABLE;
2269: }
2270: my $earlyout = 0;
1.136 raeburn 2271: my $view_permission =
2272: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.137 albertel 2273: $env{'form.group'} =~ s/\W//g;
1.138 albertel 2274: $group = $env{'form.group'};
1.191 raeburn 2275: if ($group ne '') {
2276: ($uname,$udom) = &get_name_dom($group);
1.99 raeburn 2277: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98 albertel 2278: $group);
2279: if (%curr_groups) {
1.132 raeburn 2280: my %grp_content = &Apache::longroup::get_group_settings(
2281: $curr_groups{$group});
2282: $grp_desc = &unescape($grp_content{'description'});
1.94 raeburn 2283: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
2284: $env{'request.course.id'}.'/'.$group))) {
1.138 albertel 2285: $portfolio_root = &get_portfolio_root();
1.94 raeburn 2286: } else {
1.185 banghart 2287: $r->print(&mt('You do not have the privileges required to access the shared files space for this group.'));
1.94 raeburn 2288: $earlyout = 1;
2289: }
2290: } else {
1.185 banghart 2291: $r->print(&mt('Not a valid group for this course'));
1.94 raeburn 2292: $earlyout = 1;
2293: }
1.212 weissno 2294: $title = &mt('Group portfolio for [_1]', $group);
1.94 raeburn 2295: } else {
1.185 banghart 2296: $r->print(&mt('Invalid group'));
1.94 raeburn 2297: $earlyout = 1;
2298: }
2299: if ($earlyout) { return OK; }
1.126 raeburn 2300: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
1.120 raeburn 2301: $can_modify = 1;
2302: $can_delete = 1;
1.126 raeburn 2303: $can_upload = 1;
2304: $can_setacl = 1;
2305: } else {
2306: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
2307: $can_setacl = 1;
2308: }
2309: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
2310: $can_upload = 1;
2311: }
2312: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
2313: $can_modify = 1;
2314: }
2315: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
2316: $can_delete = 1;
2317: }
1.120 raeburn 2318: }
1.94 raeburn 2319: } else {
2320: ($uname,$udom) = &get_name_dom();
2321: $portfolio_root = &get_portfolio_root();
1.211 schafran 2322: $title = &mt('My Space');
1.120 raeburn 2323: $can_modify = 1;
2324: $can_delete = 1;
2325: $can_upload = 1;
2326: $can_setacl = 1;
1.94 raeburn 2327: }
2328:
1.138 albertel 2329: my $port_path = &get_port_path();
1.24 albertel 2330: &Apache::loncommon::no_cache($r);
2331: &Apache::loncommon::content_type($r,'text/html');
2332: $r->send_http_header;
2333: # Give the LON-CAPA page header
1.203 raeburn 2334: my $brcrum = [{href=>"/adm/portfolio",text=>"Portfolio Manager"}];
2335:
1.82 albertel 2336: if ($env{"form.mode"} eq 'selectfile'){
1.96 albertel 2337: $r->print(&Apache::loncommon::start_page($title,undef,
1.97 albertel 2338: {'only_body' => 1}));
1.108 raeburn 2339: } elsif ($env{'form.action'} eq 'rolepicker') {
2340: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
2341: {'no_nav_bar' => 1, }));
1.205 raeburn 2342: } elsif ($caller eq 'coursegrp_portfolio') {
2343: $r->print(&Apache::loncommon::start_page($title));
1.74 banghart 2344: } else {
1.203 raeburn 2345: $r->print(&Apache::loncommon::start_page($title,undef,
2346: {'bread_crumbs' => $brcrum}));
1.205 raeburn 2347: if (!&Apache::lonnet::usertools_access($uname,$udom,'portfolio')) {
2348: $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
2349: &mt('This is a result of one of the following:').'<ul>'.
2350: '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
2351: '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
2352: '</ul>');
2353: $r->print(&Apache::loncommon::end_page());
2354: return OK;
2355: }
1.74 banghart 2356: }
1.24 albertel 2357: $r->rflush();
1.175 raeburn 2358: my ($blocked,$blocktext) =
2359: &Apache::loncommon::blocking_status('port',$uname,$udom);
2360: if ($blocked) {
2361: $r->print($blocktext);
2362: $r->print(&Apache::loncommon::end_page());
2363: return OK;
2364: }
1.88 albertel 2365: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.185 banghart 2366: $r->print('<span class="LC_error">');
1.188 bisitz 2367: $r->print(&mt('No file was selected to upload.').' ');
2368: $r->print(&mt('To upload a file, click <strong>Browse...</strong> and select a file, then click <strong>Upload</strong>.'));
1.185 banghart 2369: $r->print('</span>');
1.40 banghart 2370: }
1.82 albertel 2371: if ($env{'form.meta'}) {
1.94 raeburn 2372: &open_form($r,$url);
1.185 banghart 2373: $r->print(&mt('Edit the meta data').'<br />');
1.137 albertel 2374: &close_form($r,$url);
1.70 banghart 2375: }
1.82 albertel 2376: if ($env{'form.store'}) {
1.70 banghart 2377: }
2378:
1.82 albertel 2379: if ($env{'form.uploaddoc.filename'}) {
1.120 raeburn 2380: if ($can_upload) {
1.137 albertel 2381: &upload($r,$url,$group);
1.120 raeburn 2382: } else {
1.138 albertel 2383: &missing_priv($r,$url,'upload');
1.120 raeburn 2384: }
1.176 albertel 2385: } elsif ($env{'form.action'} eq 'upload_embedded') {
2386: if ($can_upload) {
1.195 raeburn 2387: my $disk_quota = &get_quota($group);
2388: my $getpropath = 1;
2389: my $current_disk_usage =
2390: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
2391: $r->print(
2392: &Apache::loncommon::upload_embedded('portfolio',$port_path,$uname,$udom,
2393: $group,$portfolio_root,$group,$disk_quota,$current_disk_usage));
2394: $r->print(&done(undef,$url));
1.176 albertel 2395: } else {
2396: &missing_priv($r,$url,'upload');
2397: }
1.82 albertel 2398: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.120 raeburn 2399: if ($can_delete) {
1.164 raeburn 2400: &delete_confirmed($r,$url,$group);
1.120 raeburn 2401: } else {
1.138 albertel 2402: &missing_priv($r,$url,'delete');
1.120 raeburn 2403: }
1.82 albertel 2404: } elsif ($env{'form.action'} eq 'delete') {
1.120 raeburn 2405: if ($can_delete) {
1.191 raeburn 2406: &delete($r,$url,$group);
1.120 raeburn 2407: } else {
1.138 albertel 2408: &missing_priv($r,$url,'delete');
1.120 raeburn 2409: }
1.82 albertel 2410: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.120 raeburn 2411: if ($can_delete) {
1.191 raeburn 2412: &delete_dir_confirmed($r,$url,$group);
1.120 raeburn 2413: } else {
1.138 albertel 2414: &missing_priv($r,$url,'delete');
1.120 raeburn 2415: }
2416: } elsif ($env{'form.action'} eq 'deletedir') {
2417: if ($can_delete) {
1.137 albertel 2418: &delete_dir($r,$url);
1.120 raeburn 2419: } else {
1.138 albertel 2420: &missing_priv($r,$url,'delete');
1.120 raeburn 2421: }
1.82 albertel 2422: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.120 raeburn 2423: if ($can_modify) {
1.164 raeburn 2424: &rename_confirmed($r,$url,$group);
1.120 raeburn 2425: } else {
1.138 albertel 2426: &missing_priv($r,$url,'rename');
1.120 raeburn 2427: }
1.82 albertel 2428: } elsif ($env{'form.rename'}) {
2429: $env{'form.selectfile'} = $env{'form.rename'};
2430: $env{'form.action'} = 'rename';
1.120 raeburn 2431: if ($can_modify) {
1.191 raeburn 2432: &rename($r,$url,$group);
1.120 raeburn 2433: } else {
1.138 albertel 2434: &missing_priv($r,$url,'rename');
1.120 raeburn 2435: }
1.104 raeburn 2436: } elsif ($env{'form.access'}) {
2437: $env{'form.selectfile'} = $env{'form.access'};
1.170 raeburn 2438: if (!defined($env{'form.action'})) {
2439: $env{'form.action'} = 'chgaccess';
2440: }
2441: &display_access($r,$url,$group,$can_setacl,$port_path,$env{'form.action'});
2442: } elsif (($env{'form.action'} eq 'chgaccess') ||
2443: ($env{'form.action'} eq 'chgconditions')) {
1.120 raeburn 2444: if ($can_setacl) {
1.137 albertel 2445: &update_access($r,$url,$group,$port_path);
1.120 raeburn 2446: } else {
1.138 albertel 2447: &missing_priv($r,$url,'setacl');
1.120 raeburn 2448: }
1.108 raeburn 2449: } elsif ($env{'form.action'} eq 'rolepicker') {
1.120 raeburn 2450: if ($can_setacl) {
2451: &role_options_window($r);
2452: } else {
1.138 albertel 2453: &missing_priv($r,$url,'setacl');
1.120 raeburn 2454: }
1.82 albertel 2455: } elsif ($env{'form.createdir'}) {
1.120 raeburn 2456: if ($can_upload) {
1.191 raeburn 2457: &createdir($r,$url,$group);
1.120 raeburn 2458: } else {
1.138 albertel 2459: &missing_priv($r,$url,'upload');
1.120 raeburn 2460: }
1.82 albertel 2461: } elsif ($env{'form.lockinfo'}) {
1.137 albertel 2462: &lock_info($r,$url,$group);
1.24 albertel 2463: } else {
2464: my $current_path='/';
1.82 albertel 2465: if ($env{'form.currentpath'}) {
2466: $current_path = $env{'form.currentpath'};
1.24 albertel 2467: }
1.132 raeburn 2468: if ($caller eq 'coursegrp_portfolio') {
2469: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.137 albertel 2470: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
1.132 raeburn 2471: }
1.192 raeburn 2472: my @dir_list=&get_dir_list($portfolio_root,$current_path,$group);
1.46 albertel 2473: if ($dir_list[0] eq 'no_such_dir'){
2474: # two main reasons for this:
2475: # 1) never been here, so directory structure not created
2476: # 2) back-button navigation after deleting a directory
2477: if ($current_path eq '/'){
1.100 albertel 2478: &Apache::lonnet::mkdiruserfile($uname,$udom,
1.138 albertel 2479: &get_port_path());
1.46 albertel 2480: } else {
2481: # some directory that snuck in get rid of the directory
2482: # from the recent pulldown, just in case
2483: &Apache::lonhtmlcommon::remove_recent('portfolio',
2484: [$current_path]);
2485: $current_path = '/'; # force it back to the root
2486: }
2487: # now grab the directory list again, for the first time
1.192 raeburn 2488: @dir_list=&get_dir_list($portfolio_root,$current_path,$group);
1.43 banghart 2489: }
1.46 albertel 2490: # need to know if directory is empty so it can be removed if desired
2491: my $is_empty=(@dir_list == 2);
1.137 albertel 2492: &display_common($r,$url,$current_path,$is_empty,\@dir_list,
1.206 raeburn 2493: $can_upload,$group);
1.138 albertel 2494: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
1.137 albertel 2495: $can_upload,$can_modify,$can_delete,$can_setacl);
1.95 albertel 2496: $r->print(&Apache::loncommon::end_page());
1.30 banghart 2497: }
1.90 albertel 2498: return OK;
1.2 banghart 2499: }
1.120 raeburn 2500:
1.1 banghart 2501: 1;
2502: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>