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