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