Annotation of loncom/interface/portfolio.pm, revision 1.138
1.125 albertel 1: # The LearningOnline Network
2: # portfolio browser
3: #
1.138 ! albertel 4: # $Id: portfolio.pm,v 1.137 2006/07/19 14:57:18 albertel 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: }
63: }
64:
1.16 banghart 65: # receives a file name and path stub from username/userfiles/portfolio/
66: # returns an anchor tag consisting encoding filename and currentpath
1.23 albertel 67: sub make_anchor {
1.94 raeburn 68: my ($url, $filename, $current_path, $current_mode, $field_name,
1.137 albertel 69: $continue_select) = @_;
1.83 banghart 70: if ($continue_select ne 'true') {$continue_select = 'false'};
1.113 albertel 71: my $anchor = '<a href="'.$url.'?selectfile='.$filename.'&currentpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name;
1.138 ! albertel 72: $anchor .= &group_args();
1.94 raeburn 73: $anchor .= '">'.$filename.'</a>';
1.8 albertel 74: return $anchor;
1.6 banghart 75: }
1.138 ! albertel 76:
1.24 albertel 77: my $dirptr=16384;
1.48 banghart 78: sub display_common {
1.137 albertel 79: my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload)=@_;
1.138 ! albertel 80: my $namespace = &get_namespace();
! 81: my $port_path = &get_port_path();
1.120 raeburn 82: if ($can_upload) {
1.137 albertel 83: my $groupitem = &group_form_data();
84:
1.120 raeburn 85: my $iconpath= $r->dir_config('lonIconsURL') . "/";
86: my %text=&Apache::lonlocal::texthash(
87: 'upload' => 'Upload',
1.88 albertel 88: 'upload_label' =>
89: 'Upload file to current directory:',
90: 'createdir' => 'Create Subdirectory',
91: 'createdir_label' =>
92: 'Create subdirectory in current directory:');
1.120 raeburn 93: my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
94: $r->print(<<"TABLE");
1.114 albertel 95: <table id="LC_portfolio_actions">
96: <tr id="LC_portfolio_upload">
97: <td class="LC_label">
1.113 albertel 98: $text{'upload_label'}
99: </td>
1.120 raeburn 100: <td class="LC_value">
1.113 albertel 101: <form method="post" enctype="multipart/form-data" action="$escuri">
1.120 raeburn 102: $groupitem
1.88 albertel 103: <input name="uploaddoc" type="file" />
104: <input type="hidden" name="currentpath" value="$current_path" />
105: <input type="hidden" name="action" value="$env{"form.action"}" />
106: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
107: <input type="hidden" name="mode" value="$env{"form.mode"}" />
108: <input type="submit" name="storeupl" value="$text{'upload'}" />
1.113 albertel 109: </form>
110: </td>
111: </tr>
1.114 albertel 112: <tr id="LC_portfolio_createdir">
113: <td class="LC_label">
1.113 albertel 114: $text{'createdir_label'}
115: </td>
1.114 albertel 116: <td class="LC_value">
1.113 albertel 117: <form method="post" action="$escuri">
1.94 raeburn 118: <input name="newdir" type="input" />$groupitem
1.88 albertel 119: <input type="hidden" name="currentpath" value="$current_path" />
120: <input type="hidden" name="action" value="$env{"form.action"}" />
121: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
122: <input type="hidden" name="mode" value="$env{"form.mode"}" />
123: <input type="submit" name="createdir" value="$text{'createdir'}" />
1.113 albertel 124: </form>
125: </td>
126: </tr>
1.88 albertel 127: </table>
128: TABLE
1.120 raeburn 129: }
1.24 albertel 130: my @tree = split (/\//,$current_path);
1.137 albertel 131: $r->print('<span class="LC_current_location">'.&make_anchor($url,$port_path,'/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"}).'/');
1.19 banghart 132: if (@tree > 1){
133: my $newCurrentPath = '';
134: for (my $i = 1; $i< @tree; $i++){
135: $newCurrentPath .= $tree[$i].'/';
1.137 albertel 136: $r->print(&make_anchor($url,$tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"}).'/');
1.19 banghart 137: }
138: }
1.117 albertel 139: $r->print('</span>');
1.94 raeburn 140: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
1.137 albertel 141: $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.&group_args());
1.94 raeburn 142: $r->print('">'.
143: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
1.22 albertel 144: 'this.form.submit();'));
1.21 banghart 145: $r->print("</form>");
1.48 banghart 146: }
1.137 albertel 147:
1.134 banghart 148: sub display_directory_line {
1.137 albertel 149: my ($r,$select_mode,$fullpath, $filename, $mtime, $size, $css_class,
150: $line, $access_controls, $curr_access, $now, $version_flag,
151: $href_location, $url, $current_path, $access_admin_text)=@_;
1.135 banghart 152: # my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1.137 albertel 153: $r->print('<tr class="'.$css_class.'">');
154: $r->print($line);
155: $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" /></td>');
156: $r->print('<td>'.$$version_flag{$filename}.'<a href="'.$href_location.$filename.'">'.
157: $filename.'</a></td>');
158: $r->print('<td>'.$size.'</td>');
159: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
160: if ($select_mode ne 'true') {
161: $r->print('<td><span style="white-space: nowrap">'.
162: &mt($curr_access).' ');
163: $r->print('<a href="'.$url.'?access='.$filename.
164: '&currentpath='.$current_path.&group_args().
165: '">'.$access_admin_text.'</a></span></td>');
166: }
167: $r->print('</tr>'.$/);
1.134 banghart 168: }
1.137 albertel 169:
1.48 banghart 170: sub display_directory {
1.138 ! albertel 171: my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
1.137 albertel 172: $can_modify,$can_delete,$can_setacl)=@_;
1.48 banghart 173: my $iconpath= $r->dir_config('lonIconsURL') . "/";
174: my $display_out;
1.77 banghart 175: my $select_mode;
176: my $checked_files;
1.138 ! albertel 177: my $port_path = &get_port_path();
! 178: my ($uname,$udom) = &get_name_dom();
1.120 raeburn 179: my $access_admin_text = &mt('View Status');
180: if ($can_setacl) {
181: $access_admin_text = &mt('View/Change Status');
182: }
183:
1.102 raeburn 184: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
185: $uname);
186: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
187: $current_permissions,$group);
188: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
189: my $now = time;
1.82 albertel 190: if ($env{"form.mode"} eq 'selectfile'){
1.77 banghart 191: &select_files($r);
1.94 raeburn 192: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
1.77 banghart 193: $select_mode = 'true';
194: }
1.120 raeburn 195: if ($is_empty && ($current_path ne '/') && $can_delete) {
1.137 albertel 196: $display_out = '<form method="post" action="'.$url.'">'.
197: &group_form_data().
1.30 banghart 198: '<input type="hidden" name="action" value="deletedir" />'.
199: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
200: '<input type="hidden" name="selectfile" value="" />'.
201: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
202: '</form>';
203:
1.48 banghart 204: $r->print($display_out);
1.31 albertel 205: return;
206: }
1.77 banghart 207: if ($select_mode eq 'true') {
1.113 albertel 208: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
1.119 albertel 209: $r->print('<table id="LC_browser">'.
1.77 banghart 210: '<tr><th>Select</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
211: } else {
1.113 albertel 212: $r->print('<form method="post" action="'.$url.'">');
1.119 albertel 213: $r->print('<table id="LC_browser">'.
1.102 raeburn 214: '<tr><th colspan="2">Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th><th>Current Access Status</th></tr>');
1.94 raeburn 215: }
1.137 albertel 216: $r->print("\n".&group_form_data()."\n");
217:
1.94 raeburn 218: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
219: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
1.105 banghart 220: my @dir_lines;
1.131 banghart 221: my @version_lines;
1.105 banghart 222: my %versioned;
1.26 albertel 223: foreach my $line (sort
224: {
225: my ($afile)=split('&',$a,2);
226: my ($bfile)=split('&',$b,2);
227: return (lc($afile) cmp lc($bfile));
228: } (@$dir_list)) {
1.18 banghart 229: #$strip holds directory/file name
230: #$dom
1.23 albertel 231: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1.77 banghart 232: $filename =~ s/\s+$//;
1.105 banghart 233: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
234: if ($version) {
1.131 banghart 235: push(@version_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
1.129 banghart 236: $versioned{$fname.'.'.$extension} .= $version.",";
1.131 banghart 237: } else {
238: push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
1.105 banghart 239: }
240: }
1.106 albertel 241: foreach my $line (@dir_lines) {
1.105 banghart 242: my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$line;
243: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
1.93 albertel 244: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
1.130 banghart 245: my %version_flag;
1.131 banghart 246: my $show_versions;
247: if ($env{'form.showversions'} eq $filename) {
248: $show_versions = 'true';
249: }
1.129 banghart 250: if (exists($versioned{$filename})) {
1.134 banghart 251: if ($show_versions) {
252: $version_flag{$filename} = '<a href="portfolio"><img alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" /></a>';
253: } else {
254: $version_flag{$filename} = '<a href="portfolio?showversions='.$filename.'"><img alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" /></a>';
255: }
1.129 banghart 256: } else {
1.130 banghart 257: $version_flag{$filename} = '';
1.129 banghart 258: }
1.23 albertel 259: if ($dirptr&$testdir) {
1.116 albertel 260: my $colspan='colspan="2"';
1.77 banghart 261: if ($select_mode eq 'true'){
1.116 albertel 262: undef($colspan);
1.64 banghart 263: }
1.116 albertel 264: $r->print('<tr class="LC_browser_folder"><td '.$colspan.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_closed.gif" /></td>');
1.47 banghart 265: $r->print('<td>Go to ...</td>');
1.137 albertel 266: $r->print('<td>'.$version_flag{$filename}.&make_anchor($url,$filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'}).'/</td>');
1.47 banghart 267: $r->print('</tr>');
268: } else {
1.116 albertel 269: my $css_class = 'LC_browser_file';
270: my $line;
1.129 banghart 271: my $fullpath = $current_path.$filename;
1.138 ! albertel 272: $fullpath = &prepend_group($fullpath);
1.124 albertel 273: if ($select_mode eq 'true') {
1.116 albertel 274: $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
275: if ($$checked_files{$filename} eq 'selected') {
276: $line.=" checked ";
1.77 banghart 277: }
1.116 albertel 278: $line.=' /></td>';
1.77 banghart 279: } else {
1.103 raeburn 280: if (exists $locked_files{$fullpath}) {
1.137 albertel 281: $line.='<td colspan="2"><a href="'.$url.'?lockinfo='.$current_path.$filename.&group_args().'">Locked</a></td>';
1.116 albertel 282: $css_class= 'LC_browser_file_locked';
1.77 banghart 283: } else {
1.120 raeburn 284: if (!$can_modify) {
285: $line .= '<td colspan="2">';
286: } else {
287: $line .= '<td>';
288: }
289: if ($can_delete) {
290: $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
291: }
292: if ($can_modify) {
293: my $cat='<img alt="'.&mt('Catalog Information').
294: '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
1.137 albertel 295: $line .= '<a href="'.$url.'?rename='.$filename.'&currentpath='.$current_path.&group_args().'">Rename</a>';
1.130 banghart 296: $line .= '</td><td>'.$version_flag{$filename}.'<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
1.120 raeburn 297: }
298: $line .= '</td>';
1.77 banghart 299: }
1.61 banghart 300: }
1.124 albertel 301: my $curr_access;
302: if ($select_mode ne 'true') {
303: my $pub_access = 0;
304: my $guest_access = 0;
305: my $cond_access = 0;
306: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
307: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
308: if (($now > $start) && (!$end || $end > $now)) {
309: if ($scope eq 'public') {
310: $pub_access = 1;
311: } elsif ($scope eq 'guest') {
312: $guest_access = 1;
313: } else {
314: $cond_access = 1;
315: }
316: }
317: }
318: if (!$pub_access && !$guest_access && !$cond_access) {
319: $curr_access = &mt('Private');
320: } else {
321: my @allaccesses;
322: if ($pub_access) {
323: push(@allaccesses,&mt('Public'));
324: }
325: if ($guest_access) {
326: push(@allaccesses,&mt('Passphrase-protected'));
327: }
328: if ($cond_access) {
329: push(@allaccesses,&mt('Conditional'));
330: }
331: $curr_access = join('+ ',@allaccesses);
332: }
333: }
1.135 banghart 334: &display_directory_line($r,$select_mode,$fullpath, $filename, $mtime, $size, $css_class, $line, \%access_controls, $curr_access,
1.137 albertel 335: $now, \%version_flag, $href_location, $url, $current_path, $access_admin_text);
1.135 banghart 336: # $r->print('<tr class="'.$css_class.'">');
337: # $r->print($line);
338: # $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" /></td>');
339: # $r->print('<td>'.$version_flag{$filename}.'<a href="'.$href_location.$filename.'">'.
340: # $filename.'</a></td>');
341: # $r->print('<td>'.$size.'</td>');
342: # $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
343: # if ($select_mode ne 'true') {
344: # $r->print('<td><span style="white-space: nowrap">'.
345: # &mt($curr_access).' ');
346: # $r->print('<a href="'.$url.'?access='.$filename.
1.137 albertel 347: # '&currentpath='.$current_path.&group_args().
1.135 banghart 348: # '">'.$access_admin_text.'</a></span></td>');
349: # }
350: # $r->print('</tr>'.$/);
1.134 banghart 351: if ($show_versions) {
1.135 banghart 352: &display_directory_line($r,$select_mode,$fullpath, $css_class, $line, \%access_controls,
1.137 albertel 353: $now, \%version_flag, $href_location, $url, $current_path, $access_admin_text);
1.135 banghart 354:
1.134 banghart 355: }
1.47 banghart 356: }
357: }
358: }
1.77 banghart 359: if ($select_mode eq 'true') {
360: $r->print('</table>
1.127 albertel 361: <input type="hidden" name="continue" value="true" />
362: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
363: <input type="hidden" name="mode" value="selectfile" />
1.60 banghart 364: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
1.48 banghart 365: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
366: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77 banghart 367: </form>');
368: } else {
1.120 raeburn 369: $r->print('</table>');
370: if ($can_delete) {
371: $r->print('
1.77 banghart 372: <input type="submit" name="doit" value="Delete Checked Files" />
373: <input type="hidden" name="action" value="delete" />
374: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.120 raeburn 375: </form>'
376: );
377: }
1.77 banghart 378: }
1.47 banghart 379: }
1.72 banghart 380:
1.24 albertel 381: sub open_form {
1.94 raeburn 382: my ($r,$url)=@_;
1.65 banghart 383: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.102 raeburn 384: $r->print('<form name="portform" method="post" action="'.$url.'">');
1.24 albertel 385: $r->print('<input type="hidden" name="action" value="'.
1.82 albertel 386: $env{'form.action'}.'" />');
1.24 albertel 387: $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65 banghart 388: foreach (@files) {
389: $r->print('<input type="hidden" name="selectfile" value="'.
390: $_.'" />');
391: }
1.24 albertel 392: $r->print('<input type="hidden" name="currentpath" value="'.
1.82 albertel 393: $env{'form.currentpath'}.'" />');
1.24 albertel 394: }
395:
396: sub close_form {
1.137 albertel 397: my ($r,$url,$button_text)=@_;
1.108 raeburn 398: if (!defined($button_text)) {
399: $button_text = {
400: 'continue' => &mt('Continue'),
401: 'cancel' => &mt('Cancel'),
402: };
403: }
1.138 ! albertel 404: $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
1.137 albertel 405: $r->print(&group_form_data().'</p></form>');
1.112 albertel 406: $r->print('<form action="'.$url.'" method="post">
1.24 albertel 407: <p>
408: <input type="hidden" name="currentpath" value="'.
1.137 albertel 409: $env{'form.currentpath'}.'" />'.
410: &group_form_data());
1.108 raeburn 411: $r->print("\n".' <input type="submit" value="'.$button_text->{'cancel'}.'" />
1.94 raeburn 412: </p></form>');
1.24 albertel 413: }
414:
415: sub display_file {
1.27 albertel 416: my ($path,$filename)=@_;
1.65 banghart 417: my $display_file_text;
1.116 albertel 418: my $file_start='<span class="LC_filename">';
419: my $file_end='</span>';
1.82 albertel 420: if (!defined($path)) { $path=$env{'form.currentpath'}; }
1.65 banghart 421: if (!defined($filename)) {
1.82 albertel 422: $filename=$env{'form.selectfile'};
1.116 albertel 423: $display_file_text = $file_start.$path.$filename.$file_end;
1.65 banghart 424: } elsif (ref($filename) eq "ARRAY") {
1.116 albertel 425: foreach my $file (@$filename) {
426: $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
1.65 banghart 427: }
428: } elsif (ref($filename) eq "SCALAR") {
1.116 albertel 429: $display_file_text = $file_start.$path.$$filename.$file_end;
430: } else {
431: $display_file_text = $file_start.$path.$filename.$file_end;
1.65 banghart 432: }
433: return $display_file_text;
1.24 albertel 434: }
435:
436: sub done {
1.137 albertel 437: my ($message,$url)=@_;
1.76 banghart 438: unless (defined $message) {
439: $message='Done';
440: }
1.94 raeburn 441: my $result = '<h3><a href="'.$url.'?currentpath='.
442: $env{'form.currentpath'}.
443: '&fieldname='.$env{'form.fieldname'}.
1.137 albertel 444: '&mode='.$env{'form.mode'}.
445: &group_args();
1.94 raeburn 446: $result .= '">'.&mt($message).'</a></h3>';
447: return $result;
1.24 albertel 448: }
449:
450: sub delete {
1.138 ! albertel 451: my ($r,$url)=@_;
1.55 banghart 452: my @check;
1.82 albertel 453: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.138 ! albertel 454: $file_name = &prepend_group($file_name);
1.65 banghart 455: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.138 ! albertel 456: my ($uname,$udom) = &get_name_dom();
1.94 raeburn 457: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.55 banghart 458: $r->print ("The file is locked and cannot be deleted.<br />");
1.137 albertel 459: $r->print(&done('Back',$url));
1.55 banghart 460: } else {
1.66 banghart 461: if (scalar(@files)) {
1.94 raeburn 462: &open_form($r,$url);
1.66 banghart 463: $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
1.137 albertel 464: &close_form($r,$url);
1.66 banghart 465: } else {
466: $r->print("No file was checked to delete.<br />");
1.137 albertel 467: $r->print(&done(undef,$url));
1.66 banghart 468: }
1.55 banghart 469: }
1.24 albertel 470: }
471:
472: sub delete_confirmed {
1.138 ! albertel 473: my ($r,$url)=@_;
1.65 banghart 474: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
475: my $result;
1.138 ! albertel 476: my ($uname,$udom) = &get_name_dom();
! 477: my $port_path = &get_port_path();
1.65 banghart 478: foreach my $delete_file (@files) {
1.94 raeburn 479: $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.82 albertel 480: $env{'form.currentpath'}.
1.65 banghart 481: $delete_file);
482: if ($result ne 'ok') {
1.116 albertel 483: $r->print('<span class="LC_error"> An error occured ('.$result.
484: ') while trying to delete '.&display_file(undef, $delete_file).'</span><br />');
1.65 banghart 485: }
1.24 albertel 486: }
1.137 albertel 487: $r->print(&done(undef,$url));
1.24 albertel 488: }
489:
1.30 banghart 490: sub delete_dir {
1.137 albertel 491: my ($r,$url)=@_;
1.94 raeburn 492: &open_form($r,$url);
1.30 banghart 493: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
1.137 albertel 494: &close_form($r,$url);
1.30 banghart 495: }
496:
497: sub delete_dir_confirmed {
1.138 ! albertel 498: my ($r,$url)=@_;
1.82 albertel 499: my $directory_name = $env{'form.currentpath'};
1.81 albertel 500: $directory_name =~ s|/$||; # remove any trailing slash
1.138 ! albertel 501: my ($uname,$udom) = &get_name_dom();
! 502: my $namespace = &get_namespace();
! 503: my $port_path = &get_port_path();
1.94 raeburn 504: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.30 banghart 505: $directory_name);
1.32 banghart 506:
1.30 banghart 507: if ($result ne 'ok') {
1.116 albertel 508: $r->print('<span class="LC_error"> An error occured (dir) ('.$result.
509: ') while trying to delete '.$directory_name.'</span><br />');
1.32 banghart 510: } else {
1.41 banghart 511: # now remove from recent
512: # $r->print('<br /> removing '.$directory_name.'<br /');
1.94 raeburn 513: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
1.32 banghart 514: my @dirs = split m!/!, $directory_name;
515:
516: # $directory_name =~ m/^(\/*\/)(\/*.)$/;
517: $directory_name='/';
518: for (my $i=1; $i < (@dirs - 1); $i ++){
519: $directory_name .= $dirs[$i].'/';
520: }
1.82 albertel 521: $env{'form.currentpath'} = $directory_name;
1.30 banghart 522: }
1.137 albertel 523: $r->print(&done(undef,$url));
1.30 banghart 524: }
525:
1.24 albertel 526: sub rename {
1.138 ! albertel 527: my ($r,$url)=@_;
1.82 albertel 528: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
1.138 ! albertel 529: my ($uname,$udom) = &get_name_dom();
! 530: $file_name = &prepend_group($file_name);
1.94 raeburn 531: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.55 banghart 532: $r->print ("The file is locked and cannot be renamed.<br />");
1.137 albertel 533: $r->print(&done(undef,$url));
1.55 banghart 534: } else {
1.94 raeburn 535: &open_form($r,$url);
1.55 banghart 536: $r->print('<p>'.&mt('Rename').' '.&display_file().' to
537: <input name="filenewname" type="input" size="50" />?</p>');
1.137 albertel 538: &close_form($r,$url);
1.55 banghart 539: }
1.24 albertel 540: }
541:
542: sub rename_confirmed {
1.138 ! albertel 543: my ($r,$url)=@_;
1.82 albertel 544: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.138 ! albertel 545: my ($uname,$udom) = &get_name_dom();
! 546: my $port_path = &get_port_path();
1.27 albertel 547: if ($filenewname eq '') {
1.116 albertel 548: $r->print('<span class="LC_error">'.
1.27 albertel 549: &mt("Error: no valid filename was provided to rename to.").
1.116 albertel 550: '</span><br />');
1.137 albertel 551: $r->print(&done(undef,$url));
1.27 albertel 552: return;
553: }
554: my $result=
1.94 raeburn 555: &Apache::lonnet::renameuserfile($uname,$udom,
556: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
557: $port_path.$env{'form.currentpath'}.$filenewname);
1.27 albertel 558: if ($result ne 'ok') {
1.116 albertel 559: $r->print('<span class="LC_error">'.
560: &mt('An errror occured ([_1]) while trying to rename [_2]'
561: .' to [_3]',$result,&display_file(),
562: &display_file('',$filenewname)).'</span><br />');
1.27 albertel 563: }
1.82 albertel 564: if ($filenewname ne $env{'form.filenewname'}) {
1.116 albertel 565: $r->print(&mt("The new file name was changed from:<br />[_1] to [_2]",
566: '<strong>'.&display_file('',$env{'form.filenewname'}).'</strong>',
567: '<strong>'.&display_file('',$filenewname).'</strong>'));
1.66 banghart 568: }
1.137 albertel 569: $r->print(&done(undef,$url));
1.27 albertel 570: }
1.102 raeburn 571:
1.104 raeburn 572: sub display_access {
1.137 albertel 573: my ($r,$url,$group,$can_setacl,$port_path) = @_;
1.138 ! albertel 574: my ($uname,$udom) = &get_name_dom();
1.104 raeburn 575: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
1.138 ! albertel 576: $file_name = &prepend_group($file_name);
1.104 raeburn 577: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
578: $uname);
579: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
1.120 raeburn 580: my $aclcount = keys(%access_controls);
1.133 raeburn 581: my $header = '<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>';
1.123 albertel 582: my $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.').'<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.').'</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.').'</li><li>'.&mt('Conditional files are accessible to logged-in users with accounts in the LON-CAPA network, who satisfy the conditions you set.').'<br />'.&mt('The conditions can include affiliation with a particular course or group, or a user account in a specific domain.').'<br />'.&mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'</li></ul>';
1.120 raeburn 583: if ($can_setacl) {
584: &open_form($r,$url);
585: $r->print($header.$info);
586: &access_setting_table($r,$access_controls{$file_name});
587: my $button_text = {
1.108 raeburn 588: 'continue' => &mt('Proceed'),
589: 'cancel' => &mt('Back to directory listing'),
590: };
1.137 albertel 591: &close_form($r,$url,$button_text);
1.120 raeburn 592: } else {
593: $r->print($header);
594: if ($aclcount) {
595: $r->print($info);
596: }
1.137 albertel 597: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
1.120 raeburn 598: }
599: }
600:
601: sub view_access_settings {
1.137 albertel 602: my ($r,$url,$access_controls,$aclcount) = @_;
1.120 raeburn 603: my ($showstart,$showend);
604: my %todisplay;
605: foreach my $key (sort(keys(%{$access_controls}))) {
606: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
607: $todisplay{$scope}{$key} = $$access_controls{$key};
608: }
609: if ($aclcount) {
610: $r->print(&mt('<h4>Current access controls defined for this file:</h4>'));
611: $r->print(&Apache::loncommon::start_data_table());
612: $r->print(&Apache::loncommon::start_data_table_header_row());
613: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
614: '</th><th>'.&mt('Additional information').'</th>');
615: $r->print(&Apache::loncommon::end_data_table_header_row());
616: my $count = 1;
617: my $chg = 'none';
618: &build_access_summary($r,$count,$chg,%todisplay);
619: $r->print(&Apache::loncommon::end_data_table());
620: } else {
621: $r->print(&mt('No access control settings currently exist for this file.<br />' ));
622: }
623: $r->print('<br /><a href="'.$url.'?currentpath='.$env{'form.currentpath'}.
1.137 albertel 624: &group_args().'">'.&mt('Return to directory listing').'</a>');
1.120 raeburn 625: return;
1.104 raeburn 626: }
627:
1.120 raeburn 628: sub build_access_summary {
629: my ($r,$count,$chg,%todisplay) = @_;
630: my ($showstart,$showend);
631: my %scope_desc = (
632: public => 'Public',
633: guest => 'Passphrase-protected',
634: domains => 'Conditional: domain-based',
635: users => 'Conditional: user-based',
636: course => 'Conditional: course-based',
637: group => 'Conditional: group-based',
638: );
639: my @allscopes = ('public','guest','domains','users','course','group');
640: foreach my $scope (@allscopes) {
641: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
642: next;
643: }
644: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
645: if ($count) {
646: $r->print(&Apache::loncommon::start_data_table_row());
647: }
648: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
649: my $content = $todisplay{$scope}{$key};
650: if ($chg eq 'delete') {
651: $showstart = &mt('Deleted');
652: $showend = $showstart;
653: } else {
654: $showstart = localtime($start);
655: if ($end == 0) {
656: $showend = &mt('No end date');
657: } else {
658: $showend = localtime($end);
659: }
660: }
661: $r->print('<td>'.&mt($scope_desc{$scope}));
662: if (($scope eq 'course') || ($scope eq 'group')) {
663: if ($chg ne 'delete') {
664: my $cid = $content->{'domain'}.'_'.$content->{'number'};
665: my %course_description = &Apache::lonnet::coursedescription($cid);
666: $r->print('<br />('.$course_description{'description'}.')');
667: }
668: }
669: $r->print('</td><td>'.&mt('Start: ').$showstart.
670: '<br />'.&mt('End: ').$showend.'</td><td>');
671: if ($chg ne 'delete') {
672: if ($scope eq 'guest') {
673: $r->print(&mt('Passphrase').': '.$content->{'password'});
674: } elsif ($scope eq 'course' || $scope eq 'group') {
675: $r->print('<table><tr>');
676: $r->print('<th>'.&mt('Roles').'</th><th>'.
677: &mt('Access').'</th><th>'.
678: &mt('Sections').'</th>');
679: if ($scope eq 'course') {
680: $r->print('<th>'.&mt('Groups').'</th>');
681: } else {
682: $r->print('<th>'.&mt('Teams').'</th>');
683: }
684: $r->print('</tr>');
685: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
686: $r->print('<tr>');
687: foreach my $item ('role','access','section','group') {
688: $r->print('<td>');
689: if ($item eq 'role') {
690: my $ucscope = $scope;
691: $ucscope =~ s/^(\w)/uc($1)/e;
692: my $role_output;
693: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
694: if ($role eq 'all') {
695: $role_output .= $role.',';
696: } elsif ($role =~ /^cr/) {
697: $role_output .= (split('/',$role))[3].',';
698: } else {
699: $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
700: }
701: }
702: $role_output =~ s/,$//;
703: $r->print($role_output);
704: } else {
705: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
706: }
1.121 albertel 707: $r->print('</tr>');
1.120 raeburn 708: }
1.121 albertel 709: $r->print("</table>");
1.120 raeburn 710: }
1.121 albertel 711: $r->print("</tr></table>");
1.120 raeburn 712: } elsif ($scope eq 'domains') {
713: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
714: } elsif ($scope eq 'users') {
715: my $curr_user_list = &sort_users($content->{'users'});
716: $r->print(&mt('Users: ').$curr_user_list);
717: } else {
718: $r->print(' ');
719: }
720: } else {
721: $r->print(' ');
722: }
723: $r->print('</td>');
724: $r->print(&Apache::loncommon::end_data_table_row());
725: $count ++;
726: }
727: }
728: }
729:
730:
1.104 raeburn 731: sub update_access {
1.137 albertel 732: my ($r,$url,$group,$port_path) = @_;
1.104 raeburn 733: my $totalprocessed = 0;
734: my %processing;
735: my %title = (
1.108 raeburn 736: 'activate' => 'New control(s) added',
737: 'delete' => 'Existing control(s) deleted',
738: 'update' => 'Existing control(s) modified',
1.104 raeburn 739: );
1.108 raeburn 740: my $changes;
1.104 raeburn 741: foreach my $chg (sort(keys(%title))) {
742: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
743: $totalprocessed += @{$processing{$chg}};
744: foreach my $num (@{$processing{$chg}}) {
745: my $scope = $env{'form.scope_'.$num};
746: my ($start,$end) = &get_dates_from_form($num);
747: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
748: if ($chg eq 'delete') {
749: $$changes{$chg}{$newkey} = 1;
750: } else {
751: $$changes{$chg}{$newkey} =
1.108 raeburn 752: &build_access_record($num,$scope,$start,$end,$chg);
1.104 raeburn 753: }
754: }
755: }
756: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.108 raeburn 757: $r->print('<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',
1.133 raeburn 758: $port_path.$file_name).'</h3>'."\n");
1.138 ! albertel 759: $file_name = &prepend_group($file_name);
! 760: my ($uname,$udom) = &get_name_dom();
1.104 raeburn 761: my ($errors,$outcome,$deloutcome,$new_values,$translation);
762: if ($totalprocessed) {
763: ($outcome,$deloutcome,$new_values,$translation) =
1.108 raeburn 764: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
765: $uname);
1.104 raeburn 766: }
1.108 raeburn 767: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
768: $uname);
1.109 albertel 769: my %access_controls =
770: &Apache::lonnet::get_access_controls($current_permissions,
771: $group,$file_name);
1.104 raeburn 772: if ($totalprocessed) {
773: if ($outcome eq 'ok') {
774: my $updated_controls = $access_controls{$file_name};
775: my ($showstart,$showend);
776: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 777: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 778: $r->print('<th>'.&mt('Type of change').'</th><th>'.
779: &mt('Access control').'</th><th>'.&mt('Dates available').
780: '</th><th>'.&mt('Additional information').'</th>');
1.110 albertel 781: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 782: foreach my $chg (sort(keys(%processing))) {
783: if (@{$processing{$chg}} > 0) {
784: if ($chg eq 'delete') {
785: if (!($deloutcome eq 'ok')) {
1.116 albertel 786: $errors .='<span class="LC_error">'.
787: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
788: '</span>';
1.104 raeburn 789: next;
790: }
791: }
792: my $numchgs = @{$processing{$chg}};
793: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 794: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
795: '.</td>');
1.104 raeburn 796: my $count = 0;
1.120 raeburn 797: my %todisplay;
1.104 raeburn 798: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
1.120 raeburn 799: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.104 raeburn 800: my $newkey = $key;
801: if ($chg eq 'activate') {
802: $newkey =~ s/^(\d+)/$$translation{$1}/;
803: }
1.120 raeburn 804: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
1.104 raeburn 805: }
1.120 raeburn 806: &build_access_summary($r,$count,$chg,%todisplay);
1.104 raeburn 807: }
808: }
809: $r->print(&Apache::loncommon::end_data_table());
810: } else {
811: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
1.116 albertel 812: $errors .= '<span class="LC_error">'.
813: &mt('A problem occurred storing access control settings: [_1]',$outcome).
814: '</span>';
1.104 raeburn 815: }
816: }
817: if ($errors) {
818: $r->print($errors);
819: }
820: }
1.108 raeburn 821: my $allnew = 0;
822: my $totalnew = 0;
823: my $status = 'new';
824: my ($firstitem,$lastitem);
825: foreach my $newitem ('course','group','domains','users') {
826: $allnew += $env{'form.new'.$newitem};
827: }
828: if ($allnew > 0) {
829: my $now = time;
830: my $then = $now + (60*60*24*180); # six months approx.
1.138 ! albertel 831: &open_form($r,$url);
1.108 raeburn 832: foreach my $newitem ('course','group','domains','users') {
833: if ($env{'form.new'.$newitem} > 0) {
834: $r->print('<br />'.&mt('Add new <b>[_1]-based</b> access control for portfolio file: <b>[_2]</b>',$newitem,$env{'form.currentpath'}.$env{'form.selectfile'}).'<br /><br />');
835: $firstitem = $totalnew;
836: $lastitem = $totalnew + $env{'form.new'.$newitem};
837: $totalnew = $lastitem;
838: my @numbers;
839: for (my $i=$firstitem; $i<$lastitem; $i++) {
840: push (@numbers,$i);
841: }
842: &display_access_row($r,$status,$newitem,\@numbers,
843: $access_controls{$file_name},$now,$then);
844: }
845: }
1.137 albertel 846: &close_form($r,$url);
1.108 raeburn 847: } else {
848: $r->print('<br /><a href="'.$url.'?access='.$env{'form.selectfile'}.
1.138 ! albertel 849: '&currentpath='.$env{'form.currentpath'}.&group_args().'">'.
1.133 raeburn 850: &mt('Display all access settings for this file').'</a>'.
851: ' '.
852: '<a href="'.$url.'?currentpath='.$env{'form.currentpath'}.
1.137 albertel 853: &group_args().'">'.&mt('Return to directory listing').'</a>');
1.108 raeburn 854: }
1.104 raeburn 855: return;
856: }
857:
858: sub build_access_record {
1.108 raeburn 859: my ($num,$scope,$start,$end,$chg) = @_;
1.109 albertel 860: my $record = {
861: type => $scope,
862: time => {
863: start => $start,
864: end => $end
865: },
866: };
867:
868: if ($scope eq 'guest') {
869: $record->{'password'} = $env{'form.password'};
1.108 raeburn 870: } elsif (($scope eq 'course') || ($scope eq 'group')) {
1.109 albertel 871: $record->{'domain'} = $env{'form.crsdom_'.$num};
872: $record->{'number'} = $env{'form.crsnum_'.$num};
1.108 raeburn 873: my @role_ids;
1.109 albertel 874: my @delete_role_ids =
875: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
876: my @preserves =
877: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
878: if (@delete_role_ids) {
879: foreach my $id (@preserves) {
880: if (grep {$_ = $id} (@delete_role_ids)) {
881: next;
882: }
883: push(@role_ids,$id);
884: }
885: } else {
886: push(@role_ids,@preserves);
887: }
888:
889: my $next_id = $env{'form.add_role_'.$num};
890: if ($next_id) {
891: push(@role_ids,$next_id);
892: }
893:
1.108 raeburn 894: foreach my $id (@role_ids) {
895: my (@roles,@accesses,@sections,@groups);
896: if (($id == $next_id) && ($chg eq 'update')) {
1.109 albertel 897: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1.108 raeburn 898: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
899: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1.109 albertel 900: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1.108 raeburn 901: } else {
902: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
903: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
904: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
905: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
906: }
1.109 albertel 907: $record->{'roles'}{$id}{'role'} = \@roles;
908: $record->{'roles'}{$id}{'access'} = \@accesses;
909: $record->{'roles'}{$id}{'section'} = \@sections;
910: $record->{'roles'}{$id}{'group'} = \@groups;
1.108 raeburn 911: }
912: } elsif ($scope eq 'domains') {
913: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1.109 albertel 914: $record->{'dom'} = \@doms;
1.108 raeburn 915: } elsif ($scope eq 'users') {
916: my $userlist = $env{'form.users_'.$num};
1.109 albertel 917: $userlist =~ s/\s+//sg;
918: my %userhash = map { ($_,1) } (split(/,/,$userlist));
919: foreach my $user (keys(%userhash)) {
1.108 raeburn 920: my ($uname,$udom) = split(/:/,$user);
1.109 albertel 921: push(@{$record->{'users'}}, {
922: 'uname' => $uname,
923: 'udom' => $udom
924: });
925: }
1.108 raeburn 926: }
1.104 raeburn 927: return $record;
928: }
929:
930: sub get_dates_from_form {
931: my ($id) = @_;
932: my $startdate;
933: my $enddate;
934: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
935: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
936: if ( exists ($env{'form.noend_'.$id}) ) {
937: $enddate = 0;
938: }
939: return ($startdate,$enddate);
940: }
941:
1.108 raeburn 942: sub sort_users {
1.109 albertel 943: my ($users) = @_;
944: my @curr_users = map {
945: $_->{'uname'}.':'.$_->{'udom'}
946: } (@{$users});
947: my $curr_user_list = join(",\n",sort(@curr_users));
1.108 raeburn 948: return $curr_user_list;
949: }
950:
1.104 raeburn 951: sub access_setting_table {
952: my ($r,$access_controls) = @_;
953: my ($public,$publictext);
1.108 raeburn 954: $publictext = &mt('Off');
1.104 raeburn 955: my ($guest,$guesttext);
1.108 raeburn 956: $guesttext = &mt('Off');
1.104 raeburn 957: my @courses = ();
958: my @groups = ();
959: my @domains = ();
960: my @users = ();
961: my $now = time;
962: my $then = $now + (60*60*24*180); # six months approx.
1.108 raeburn 963: my ($num,$scope,$publicnum,$guestnum);
964: my (%acl_count,%end,%start);
1.104 raeburn 965: foreach my $key (sort(keys(%{$access_controls}))) {
1.108 raeburn 966: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1.104 raeburn 967: if ($scope eq 'public') {
968: $public = $key;
1.108 raeburn 969: $publicnum = $num;
970: $publictext = &acl_status($start{$key},$end{$key},$now);
971: } elsif ($scope eq 'guest') {
972: $guest=$key;
973: $guestnum = $num;
974: $guesttext = &acl_status($start{$key},$end{$key},$now);
975: } elsif ($scope eq 'course') {
976: push(@courses,$key);
977: } elsif ($scope eq 'group') {
978: push(@groups,$key);
979: } elsif ($scope eq 'domains') {
980: push(@domains,$key);
981: } elsif ($scope eq 'users') {
982: push(@users,$key);
1.104 raeburn 983: }
1.108 raeburn 984: $acl_count{$scope} ++;
1.104 raeburn 985: }
1.108 raeburn 986: $r->print('<table border="0"><tr><td valign="top">');
987: $r->print('<h3>'.&mt('Public access:').' '.$publictext.'</h3>');
1.104 raeburn 988: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 989: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 990: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1.110 albertel 991: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 992: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 993: if ($public) {
994: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
995: &dateboxes($publicnum,$start{$public},$end{$public}).'</td>');
996: } else {
997: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
998: &dateboxes('0',$now,$then).'</td>');
999: }
1000: $r->print(&Apache::loncommon::end_data_table_row());
1001: $r->print(&Apache::loncommon::end_data_table());
1002: $r->print('</td><td width="40"> </td><td valign="top">');
1.120 raeburn 1003: $r->print('<h3>'.&mt('Passphrase-protected access:').' '.$guesttext.'</h3>');
1.104 raeburn 1004: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1005: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1006: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1.120 raeburn 1007: '</th><th>'. &mt('Passphrase').'</th>');
1.110 albertel 1008: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1009: $r->print(&Apache::loncommon::start_data_table_row());
1010: my $passwd;
1011: if ($guest) {
1.109 albertel 1012: $passwd = $$access_controls{$guest}{'password'};
1.108 raeburn 1013: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1014: &dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
1015: } else {
1016: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1017: &dateboxes('1',$now,$then).'</td>');
1.104 raeburn 1018: }
1.108 raeburn 1019: $r->print('<td><input type="text" size="15" name="password" value="'.
1020: $passwd.'" /></td>');
1.104 raeburn 1021: $r->print(&Apache::loncommon::end_data_table_row());
1022: $r->print(&Apache::loncommon::end_data_table());
1.123 albertel 1023: $r->print('</td></tr><tr><td colspan="3"> </td></tr><tr><td valign="top">');
1024: &access_element($r,'domains',\%acl_count,\@domains,$access_controls,$now,$then);
1025: $r->print('</td><td> </td><td valign="top">');
1026: &access_element($r,'users',\%acl_count,\@users,$access_controls,$now,$then);
1027: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
1028: if (@courses > 0 || @groups > 0) {
1029: $r->print('<td colspan="3" valign="top">');
1030: } else {
1031: $r->print('<td valign="top">');
1032: }
1033: &access_element($r,'course',\%acl_count,\@courses,$access_controls,$now,$then);
1034: $r->print('</td>');
1035: if (@courses > 0 || @groups > 0) {
1036: $r->print('</tr><tr><td colspan="3"> </td></tr><tr><td colspan="3" valign="top">');
1037: } else {
1038: $r->print('<td> </td><td valign="top">');
1039: }
1040: &access_element($r,'group',\%acl_count,\@groups,$access_controls,$now,$then);
1.108 raeburn 1041: $r->print('</td></tr></table>');
1042: }
1043:
1044: sub acl_status {
1045: my ($start,$end,$now) = @_;
1046: if ($start > $now) {
1047: return &mt('Inactive');
1048: }
1049: if ($end && $end<$now) {
1050: return &mt('Inactive');
1051: }
1052: return &mt('Active');
1053: }
1054:
1055: sub access_element {
1056: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1057: my $title = $type;
1058: $title =~ s/s$//;
1059: $title =~ s/^(\w)/uc($1)/e;
1060: $r->print('<h3>'.&mt('[_1]-based conditional access: ',$title));
1061: if ($$acl_count{$type}) {
1062: $r->print($$acl_count{$type}.' ');
1063: if ($$acl_count{$type} > 1) {
1064: $r->print(&mt('conditions'));
1065: } else {
1066: $r->print(&mt('condition'));
1067: }
1068: } else {
1069: $r->print(&mt('Off'));
1070: }
1071: $r->print('</h3>');
1072: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1073: return;
1074: }
1075:
1076: sub display_access_row {
1077: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1078: if (@{$items} > 0) {
1079: my @all_doms;
1080: my $colspan = 3;
1081: my $uctype = $type;
1082: $uctype =~ s/^(\w)/uc($1)/e;
1083: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1084: $r->print(&Apache::loncommon::start_data_table_header_row());
1085: $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
1.108 raeburn 1086: &mt('Dates available').'</th>');
1087: if (($type eq 'course') || ($type eq 'group')) {
1088: $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
1089: '</th>');
1090: $colspan ++;
1091: } elsif ($type eq 'domains') {
1092: @all_doms = &Apache::loncommon::get_domains();
1093: }
1.110 albertel 1094: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1095: foreach my $key (@{$items}) {
1.118 albertel 1096: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1097: if (($type eq 'course') || ($type eq 'group')) {
1.118 albertel 1098: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1.108 raeburn 1099: } elsif ($type eq 'domains') {
1100: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1101: $then);
1102: } elsif ($type eq 'users') {
1103: &users_row($r,$status,$key,$access_controls,$now,$then);
1104: }
1.118 albertel 1105: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1106: }
1107: if ($status eq 'old') {
1.111 albertel 1108: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1109: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1110: '</td>');
1.111 albertel 1111: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1112: }
1113: $r->print(&Apache::loncommon::end_data_table());
1114: } else {
1115: $r->print(&mt('No [_1]-based conditions defined.<br />',$type).
1116: &additional_item($type));
1117: }
1118: return;
1119: }
1120:
1.110 albertel 1121: sub course_js {
1122: return qq|
1.108 raeburn 1123: <script type="text/javascript">
1124: function setRoleOptions(caller,num,cdom,cnum,type) {
1125: addIndexnum = getCallerIndex(caller);
1126: updateIndexnum = getIndex('update',num);
1127: if (caller.checked) {
1128: document.portform.elements[updateIndexnum].checked = true;
1129: var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1130: var title = 'Roles_Chooser';
1131: var options = 'scrollbars=1,resizable=1,menubar=0';
1132: options += ',width=700,height=600';
1133: rolebrowser = open(url,title,options,'1');
1134: rolebrowser.focus();
1135: } else {
1136: for (var j=0;j<5;j++) {
1137: document.portform.elements[addIndexnum+j].value = '';
1138: }
1139: }
1140: }
1141:
1142: function getCallerIndex(caller) {
1143: for (var i=0;i<document.portform.elements.length;i++) {
1144: if (document.portform.elements[i] == caller) {
1145: return i;
1146: }
1147: }
1148: return -1;
1149: }
1150:
1151: function getIndex(name,value) {
1152: for (var i=0;i<document.portform.elements.length;i++) {
1153: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1154: return i;
1155: }
1156: }
1157: return -1;
1158: }
1159:
1160: </script>
1.110 albertel 1161: |;
1162: }
1163:
1164: sub course_row {
1.118 albertel 1165: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1.115 raeburn 1166: my $content;
1.110 albertel 1167: my $defdom = $env{'user.domain'};
1168: if ($status eq 'old') {
1.115 raeburn 1169: $content = $$access_controls{$item};
1170: $defdom = $content->{'domain'};
1.110 albertel 1171: }
1172: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1173: .&course_js();
1.108 raeburn 1174: my $crsgrptext = 'Groups';
1175: if ($type eq 'group') {
1176: $crsgrptext = 'Teams';
1177: }
1.120 raeburn 1178: my $uctype = $type;
1179: $uctype =~ s/^(\w)/uc($1)/e;
1.108 raeburn 1180: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1181: $type);
1.110 albertel 1182: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1.108 raeburn 1183: if ($status eq 'old') {
1.115 raeburn 1184: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 1185: my %course_description = &Apache::lonnet::coursedescription($cid);
1.115 raeburn 1186: $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 1187: } elsif ($status eq 'new') {
1188: $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,undef,undef,$uctype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
1189: }
1190: $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
1.118 albertel 1191: $r->print('<td><table><tr>');
1.108 raeburn 1192: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
1193: &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
1194: &mt($crsgrptext).'</th></tr>');
1195: if ($status eq 'old') {
1196: my $max_id = 0;
1.115 raeburn 1197: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1.108 raeburn 1198: if ($role_id > $max_id) {
1199: $max_id = $role_id;
1200: }
1201: $max_id ++;
1.115 raeburn 1202: my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display');
1.112 albertel 1203: $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>');
1.108 raeburn 1204: }
1.120 raeburn 1205: $r->print('</table><br />'.&mt('Add a roles-based condition').' <input type="checkbox" name ="add_role_'.$num.'" onClick="javascript:setRoleOptions(this,'."'$num','$content->{'domain'}','$content->{'number'}','$uctype'".')" value="'.$max_id.'" /><input type="hidden" name="role_'.$num.'_'.$max_id.'" /><input type="hidden" name="access_'.$num.'_'.$max_id.'" /><input type="hidden" name="section_'.$num.'_'.$max_id.'" /><input type="hidden" name="group_'.$num.'_'.$max_id.'" /></td>');
1.108 raeburn 1206: } elsif ($status eq 'new') {
1207: my $role_id = 1;
1208: my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
1209: $r->print('<tr><td><input type="checkbox" name="add_role_'.$num.'" value="'.$role_id.'" checked="checked" />'.&mt('Add').'<input type="hidden" name="grplist_'.$num.'_'.$role_id.'" /></td>'.$role_selects);
1210: $r->print('</tr></table></td>');
1211: }
1212: return;
1213: }
1214:
1215: sub domains_row {
1216: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1217: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1218: 'domains');
1.112 albertel 1219: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true">'.
1.108 raeburn 1220: ' <option value="">'.&mt('Please select').'</option>';
1221: if ($status eq 'old') {
1.109 albertel 1222: my $content = $$access_controls{$item};
1223: foreach my $dom (@{$all_doms}) {
1224: if ((@{$content->{'dom'}} > 0)
1225: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.108 raeburn 1226: $dom_select .= '<option value="'.$dom.'" selected>'.
1227: $dom.'</option>';
1228: } else {
1229: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1230: }
1231: }
1232: } else {
1233: foreach my $dom (@{$all_doms}) {
1234: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1235: }
1236: }
1.112 albertel 1237: $dom_select .= '</select>';
1.108 raeburn 1238: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1239: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1240: }
1241:
1242: sub users_row {
1243: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1244: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1245: 'users');
1246: my $curr_user_list;
1247: if ($status eq 'old') {
1.109 albertel 1248: my $content = $$access_controls{$item};
1249: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1250: }
1251: $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>');
1252: }
1253:
1254: sub additional_item {
1255: my ($type) = @_;
1256: my $output = &mt('Add new [_1] condition(s)?',$type).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1257: return $output;
1258: }
1259:
1260: sub actionbox {
1261: my ($status,$num,$scope) = @_;
1.112 albertel 1262: my $output = '<span style="white-space: nowrap"><label>';
1.108 raeburn 1263: if ($status eq 'new') {
1264: $output .= '<input type="checkbox" name="activate" value="'.$num.'" />'.
1265: &mt('Activate');
1266: } else {
1267: $output .= '<input type="checkbox" name="delete" value="'.$num.
1.112 albertel 1268: '" />'.&mt('Delete').'</label></span><br /><span style="white-space: nowrap">'.
1.108 raeburn 1269: '<label><input type="checkbox" name="update" value="'.
1270: $num.'" />'.&mt('Update');
1271: }
1.112 albertel 1272: $output .= '</label></span><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1.108 raeburn 1273: return $output;
1274: }
1275:
1276: sub dateboxes {
1277: my ($num,$start,$end) = @_;
1278: my $noend;
1279: if ($end == 0) {
1280: $noend = 'checked="checked"';
1281: }
1282: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1283: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1284: undef,undef,1);
1285: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1286: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1.112 albertel 1287: undef,undef,1). ' <span style="white-space: nowrap"><label>'.
1.108 raeburn 1288: '<input type="checkbox" name="noend_'.
1289: $num.'" '.$noend.' />'.&mt('No end date').
1.112 albertel 1290: '</label></span>';
1.108 raeburn 1291:
1292: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1293: return $output;
1294: }
1295:
1296: sub unpack_acc_key {
1297: my ($acc_key) = @_;
1298: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1299: return ($num,$scope,$end,$start);
1300: }
1301:
1302: sub set_identifiers {
1303: my ($status,$item,$now,$then,$scope) = @_;
1304: if ($status eq 'old') {
1305: return(&unpack_acc_key($item));
1306: } else {
1307: return($item,$scope,$then,$now);
1308: }
1309: }
1310:
1311: sub role_selectors {
1312: my ($num,$role_id,$status,$type,$content,$caller) = @_;
1313: my ($output,$cdom,$cnum,$longid);
1314: if ($caller eq 'display') {
1315: $longid = '_'.$num.'_'.$role_id;
1316: if ($status eq 'new') {
1317: foreach my $item ('role','access','section','group') {
1318: $output .= '<td><select name="'.$item.$longid.'">'.
1319: '<option value="">'.&mt('Pick [_1] first',$type).
1320: '</option></select></td>';
1321: }
1322: return $output;
1323: } else {
1324: $cdom = $$content{'domain'};
1325: $cnum = $$content{'number'};
1326: }
1327: } elsif ($caller eq 'rolepicker') {
1328: $cdom = $env{'form.cdom'};
1329: $cnum = $env{'form.cnum'};
1330: }
1.120 raeburn 1331: my $uctype = $type;
1332: $uctype =~ s/^(\w)/uc($1)/e;
1.108 raeburn 1333: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1.120 raeburn 1334: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$uctype);
1.108 raeburn 1335: if (!@{$sections}) {
1336: @{$sections} = ('none');
1337: } else {
1338: unshift(@{$sections},('all','none'));
1339: }
1340: if (!@{$groups}) {
1341: @{$groups} = ('none');
1342: } else {
1343: unshift(@{$groups},('all','none'));
1344: }
1345: my @allacesses = sort(keys(%{$accesshash}));
1346: my (%sectionhash,%grouphash);
1347: foreach my $sec (@{$sections}) {
1348: $sectionhash{$sec} = $sec;
1349: }
1350: foreach my $grp (@{$groups}) {
1351: $grouphash{$grp} = $grp;
1352: }
1353: my %lookup = (
1354: 'role' => $rolehash,
1355: 'access' => $accesshash,
1356: 'section' => \%sectionhash,
1357: 'group' => \%grouphash,
1358: );
1359: my @allaccesses = sort(keys(%{$accesshash}));
1360: my %allitems = (
1361: 'role' => $allroles,
1362: 'access' => \@allaccesses,
1363: 'section' => $sections,
1364: 'group' => $groups,
1365: );
1366: foreach my $item ('role','access','section','group') {
1367: $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
1368: foreach my $entry (@{$allitems{$item}}) {
1369: if ($caller eq 'display') {
1370: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1371: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1372: $output .= ' <option value="'.$entry.'" selected>'.
1373: $lookup{$item}{$entry}.'</option>';
1374: next;
1375: }
1376: }
1377: $output .= ' <option value="'.$entry.'">'.
1378: $lookup{$item}{$entry}.'</option>';
1379: }
1380: $output .= '</select>';
1381: }
1382: $output .= '</td>';
1383: return $output;
1384: }
1385:
1386: sub role_options_window {
1387: my ($r) = @_;
1388: my $cdom = $env{'form.cdom'};
1389: my $cnum = $env{'form.cnum'};
1390: my $type = $env{'form.type'};
1391: my $addindex = $env{'form.setroles'};
1.120 raeburn 1392: my $grouptitle = 'Groups';
1393: if ($type eq 'Group') {
1394: $grouptitle = 'Teams';
1395: }
1.108 raeburn 1396: my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker');
1397: $r->print(<<"END_SCRIPT");
1398: <script type="text/javascript">
1399: function setRoles() {
1400: var addidx = $addindex+1;
1401: for (var i=0; i<4; i++) {
1402: var copylist = '';
1403: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1404: if (document.rolepicker.elements[i].options[j].selected) {
1405: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1406: }
1407: }
1408: copylist = copylist.substr(0,copylist.length-1);
1409: opener.document.portform.elements[addidx+i].value = copylist;
1410: }
1411: self.close();
1412: }
1413: </script>
1414: END_SCRIPT
1415: $r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
1.120 raeburn 1416: $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($grouptitle).'</th></tr><tr>'.$role_selects.'</tr></table><br /><input type="button" name="rolepickbutton" value="Save selections" onclick="setRoles()" />');
1.108 raeburn 1417: return;
1.104 raeburn 1418: }
1419:
1.47 banghart 1420: sub select_files {
1.138 ! albertel 1421: my ($r) = @_;
1.82 albertel 1422: if ($env{'form.continue'} eq 'true') {
1.60 banghart 1423: # here we update the selections for the currentpath
1424: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 1425: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1426: if (scalar(@items)){
1.85 banghart 1427: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 1428: }
1.62 banghart 1429: } else {
1430: #empty the file for a fresh start
1.83 banghart 1431: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 1432: }
1.82 albertel 1433: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 1434: my $java_files = join ",", @files;
1435: if ($java_files) {
1436: $java_files.=',';
1.60 banghart 1437: }
1.63 banghart 1438: my $javascript =(<<ENDSMP);
1.113 albertel 1439: <script type="text/javascript">
1.48 banghart 1440: function finishSelect() {
1.62 banghart 1441: ENDSMP
1.63 banghart 1442: $javascript .= 'fileList = "'.$java_files.'";';
1443: $javascript .= (<<ENDSMP);
1.49 banghart 1444: for (i=0;i<document.forms.checkselect.length;i++) {
1445: if (document.forms.checkselect[i].checked){
1.54 banghart 1446: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 1447: }
1448: }
1.128 albertel 1449: opener.document.forms.lonhomework.$env{'form.fieldname'}.value=fileList;
1.48 banghart 1450: self.close();
1451: }
1452: </script>
1453: ENDSMP
1.63 banghart 1454: $r->print($javascript);
1.47 banghart 1455: $r->print("<h1>Select portfolio files</h1>
1.88 albertel 1456: Check as many as you wish in response to the problem.<br />");
1457: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1458: if (@otherfiles) {
1459: $r->print("<strong>Files selected from other directories:</strong><br />");
1460: foreach my $file (@otherfiles) {
1461: $r->print($file."<br />");
1462: }
1.60 banghart 1463: }
1.47 banghart 1464: }
1.138 ! albertel 1465:
1.24 albertel 1466: sub upload {
1.137 albertel 1467: my ($r,$url,$group)=@_;
1.82 albertel 1468: my $fname=$env{'form.uploaddoc.filename'};
1469: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.38 banghart 1470: my $disk_quota = 20000; # expressed in k
1.126 raeburn 1471: if (defined($group)) {
1472: my $grp_quota = &get_group_quota($group); # quota expressed in k
1473: if ($grp_quota ne '') {
1474: $disk_quota = $grp_quota;
1475: } else {
1476: $disk_quota = 0;
1477: }
1478: }
1.34 banghart 1479: $fname=&Apache::lonnet::clean_filename($fname);
1.94 raeburn 1480:
1.138 ! albertel 1481: my $portfolio_root=&get_portfolio_root();
! 1482: my ($uname,$udom) = &get_name_dom();
! 1483: my $port_path = &get_port_path();
1.38 banghart 1484: # Fixme --- Move the checking for existing file to LOND error return
1.138 ! albertel 1485: my @dir_list=&get_dir_list($portfolio_root);
1.34 banghart 1486: my $found_file = 0;
1.76 banghart 1487: my $locked_file = 0;
1.33 banghart 1488: foreach my $line (@dir_list) {
1.76 banghart 1489: my ($file_name)=split(/\&/,$line,2);
1490: if ($file_name eq $fname){
1.102 raeburn 1491: $file_name = $env{'form.currentpath'}.$file_name;
1.138 ! albertel 1492: $file_name = &prepend_group($file_name);
1.33 banghart 1493: $found_file = 1;
1.138 ! albertel 1494: # FIXME I think this is incorrect, prepend_group took care of this?
1.102 raeburn 1495: if (defined($group)) {
1496: $file_name = $group.'/'.$file_name;
1497: }
1498: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.76 banghart 1499: $locked_file = 1;
1500: }
1.33 banghart 1501: }
1502: }
1.94 raeburn 1503: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
1.87 albertel 1504: if (($current_disk_usage + $filesize) > $disk_quota){
1.116 albertel 1505: $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
1.38 banghart 1506: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.137 albertel 1507: $r->print(&done('Back',$url));
1.38 banghart 1508: }
1.76 banghart 1509: elsif ($found_file){
1510: if ($locked_file){
1.116 albertel 1511: $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
1.76 banghart 1512: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
1.137 albertel 1513: $r->print(&done('Back',$url));
1.76 banghart 1514: } else {
1.116 albertel 1515: $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
1.94 raeburn 1516: '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
1.137 albertel 1517: $r->print(&done('Back',$url));
1.76 banghart 1518: }
1.33 banghart 1519: } else {
1520: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.94 raeburn 1521: $port_path.$env{'form.currentpath'});
1.33 banghart 1522: if ($result !~ m|^/uploaded/|) {
1.116 albertel 1523: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1524: ') while trying to upload '.&display_file().'</span><br />');
1.137 albertel 1525: $r->print(&done('Back',$url));
1.76 banghart 1526: } else {
1.137 albertel 1527: $r->print(&done(undef,$url));
1.33 banghart 1528: }
1.25 albertel 1529: }
1530: }
1.126 raeburn 1531:
1.80 banghart 1532: sub lock_info {
1.137 albertel 1533: my ($r,$url,$group) = @_;
1.138 ! albertel 1534: my ($uname,$udom) = &get_name_dom();
1.102 raeburn 1535: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1536: $uname);
1.84 banghart 1537: my $file_name = $env{'form.lockinfo'};
1.138 ! albertel 1538: $file_name = &prepend_group($file_name);
1.102 raeburn 1539: if (defined($file_name) && defined($$current_permissions{$file_name})) {
1540: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1541: if (ref($array_item) eq 'ARRAY') {
1542: my $filetext;
1543: if (defined($group)) {
1544: $filetext = '<strong>'.$env{'form.lockinfo'}.
1545: '</strong> (group: '.$group.')';
1546: } else {
1547: $filetext = '<strong>'.$file_name.'</strong>';
1548: }
1549: $r->print(&mt('[_1] was submitted in response to problem: ',
1550: $filetext).
1551: '<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
1552: '</strong><br />');
1553: my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
1554: $r->print(&mt('In the course: <strong>[_1]</strong><br />',
1555: $course_description{'description'}));
1556: # $r->print('the third is '.$$array_item[2].'<br>');
1557: # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
1.85 banghart 1558: }
1.102 raeburn 1559: }
1.84 banghart 1560: }
1.137 albertel 1561: $r->print(&done('Back',$url));
1.80 banghart 1562: return 'ok';
1563: }
1.138 ! albertel 1564:
1.25 albertel 1565: sub createdir {
1.138 ! albertel 1566: my ($r,$url)=@_;
1.82 albertel 1567: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 1568: if ($newdir eq '') {
1.116 albertel 1569: $r->print('<span class="LC_error">'.
1.37 banghart 1570: &mt("Error: no directory name was provided.").
1.116 albertel 1571: '</span><br />');
1.138 ! albertel 1572: $r->print(&done(undef,$url));
1.37 banghart 1573: return;
1.94 raeburn 1574: }
1.138 ! albertel 1575: my $portfolio_root = &get_portfolio_root();
! 1576: my @dir_list=&get_dir_list($portfolio_root);
1.37 banghart 1577: my $found_file = 0;
1578: foreach my $line (@dir_list) {
1579: my ($filename)=split(/\&/,$line,2);
1580: if ($filename eq $newdir){
1581: $found_file = 1;
1582: }
1583: }
1584: if ($found_file){
1.116 albertel 1585: $r->print('<span class="LC_error">'.'Unable to create a directory named <strong>'.$newdir.
1586: ' </strong>a file or directory by that name already exists.</span><br />');
1.37 banghart 1587: } else {
1.138 ! albertel 1588: my ($uname,$udom) = &get_name_dom();
! 1589: my $port_path = &get_port_path();
1.94 raeburn 1590: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
1591: $port_path.$env{'form.currentpath'}.$newdir);
1.37 banghart 1592: if ($result ne 'ok') {
1.116 albertel 1593: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1594: ') while trying to create a new directory '.&display_file().'</span><br />');
1.37 banghart 1595: }
1.24 albertel 1596: }
1.82 albertel 1597: if ($newdir ne $env{'form.newdir'}) {
1598: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1.67 banghart 1599: }
1.137 albertel 1600: $r->print(&done(undef,$url));
1.94 raeburn 1601: }
1602:
1603: sub get_portfolio_root {
1.138 ! albertel 1604: my ($uname,$udom) = &get_name_dom();
1.137 albertel 1605: my $path;
1.138 ! albertel 1606: if (defined($env{'form.group'})) {
! 1607: $path = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
1.94 raeburn 1608: } else {
1609: $path = '/userfiles/portfolio';
1610: }
1611: return (&Apache::loncommon::propath($udom,$uname).$path);
1612: }
1613:
1.126 raeburn 1614: sub get_group_quota {
1615: my ($group) = @_;
1616: my $group_quota;
1617: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1618: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1619: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
1620: if (%curr_groups) {
1621: my %group_info = &Apache::longroup::get_group_settings(
1622: $curr_groups{$group});
1623: $group_quota = $group_info{'quota'}; #expressed in Mb
1624: if ($group_quota) {
1625: $group_quota = 1000 * $group_quota; #expressed in k
1626: }
1627: }
1628: return $group_quota;
1629: }
1630:
1.94 raeburn 1631: sub get_dir_list {
1.138 ! albertel 1632: my ($portfolio_root) = @_;
! 1633: my ($uname,$udom) = &get_name_dom();
1.94 raeburn 1634: return &Apache::lonnet::dirlist($env{'form.currentpath'},
1635: $udom,$uname,$portfolio_root);
1636: }
1637:
1638: sub get_name_dom {
1639: my ($uname,$udom);
1.138 ! albertel 1640: if (defined($env{'form.group'})) {
1.94 raeburn 1641: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1642: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
1643: } else {
1644: $udom = $env{'user.domain'};
1645: $uname = $env{'user.name'};
1646: }
1647: return ($uname,$udom);
1648: }
1649:
1.102 raeburn 1650: sub prepend_group {
1.138 ! albertel 1651: my ($filename) = @_;
! 1652: if (defined($env{'form.group'})) {
! 1653: $filename = $env{'form.group'}.$filename;
1.102 raeburn 1654: }
1655: return $filename;
1656: }
1657:
1.94 raeburn 1658: sub get_namespace {
1659: my $namespace = 'portfolio';
1.138 ! albertel 1660: if (defined($env{'form.group'})) {
! 1661: my ($uname,$udom) = &get_name_dom();
! 1662: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
1.94 raeburn 1663: }
1664: return $namespace;
1665: }
1666:
1667: sub get_port_path {
1668: my $port_path;
1.138 ! albertel 1669: if (defined($env{'form.group'})) {
! 1670: $port_path = "groups/$env{'form.group'}/portfolio";
1.94 raeburn 1671: } else {
1672: $port_path = 'portfolio';
1673: }
1674: return $port_path;
1.24 albertel 1675: }
1676:
1.120 raeburn 1677: sub missing_priv {
1.138 ! albertel 1678: my ($r,$url,$priv) = @_;
1.120 raeburn 1679: my $longtext = {
1680: upload => 'upload files',
1681: delete => 'delete files',
1682: rename => 'rename files',
1683: setacl => 'set access controls for files',
1684: };
1685: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
1686: my $rtnlink = '<a href="'.$url;
1687: if ($url =~ /\?/) {
1688: $rtnlink .= '&';
1689: } else {
1690: $rtnlink .= '?';
1691: }
1692: $rtnlink .= 'currentpath='.$escpath;
1693: $r->print(&mt('<h3>Action disallowed</h3>'));
1694: $r->print(&mt('You do not have sufficient privileges to [_1] ',
1695: $longtext->{$priv}));
1.138 ! albertel 1696: if (defined($env{'form.group'})) {
1.120 raeburn 1697: $r->print(&mt("in the group's file repository."));
1.137 albertel 1698: $rtnlink .= &group_args()
1.120 raeburn 1699: } else {
1700: $r->print(&mt('in this portfolio.'));
1701: }
1702: $rtnlink .= '">'.&mt('Return to directory listing page').'</a>';
1703: $r->print('<br />'.$rtnlink);
1704: $r->print(&Apache::loncommon::end_page());
1705: return;
1706: }
1707:
1.132 raeburn 1708: sub coursegrp_portfolio_header {
1.137 albertel 1709: my ($cdom,$cnum,$grp_desc)=@_;
1.132 raeburn 1710: my $gpterm = &Apache::loncommon::group_term();
1711: my $ucgpterm = $gpterm;
1712: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.137 albertel 1713: if ($env{'form.ref'}) {
1.136 raeburn 1714: &Apache::lonhtmlcommon::add_breadcrumb
1715: ({href=>"/adm/coursegroups",
1716: text=>"Groups",
1717: title=>"Course Groups"});
1718: }
1.132 raeburn 1719: &Apache::lonhtmlcommon::add_breadcrumb
1.138 ! albertel 1720: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
1.132 raeburn 1721: text=>"$ucgpterm: $grp_desc",
1722: title=>"Go to group's home page"},
1.137 albertel 1723: {href=>"/adm/coursegrp_portfolio?".&group_args(),
1.132 raeburn 1724: text=>"Group Portfolio",
1.136 raeburn 1725: title=>"Display group portfolio"});
1.132 raeburn 1726: my $output = &Apache::lonhtmlcommon::breadcrumbs(
1727: &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
1728: return $output;
1729: }
1730:
1731:
1.24 albertel 1732: sub handler {
1733: # this handles file management
1734: my $r = shift;
1.73 banghart 1735: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.108 raeburn 1736: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
1737: 'fieldname','mode','rename','continue','group','access','setnum',
1.136 raeburn 1738: 'cnum','cdom','type','setroles','showversions','ref']);
1.138 ! albertel 1739: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
1.94 raeburn 1740: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
1741: $url = $1.$2;
1742: $caller = $2;
1743: }
1.137 albertel 1744: my ($can_modify,$can_delete,$can_upload,$can_setacl);
1.94 raeburn 1745: if ($caller eq 'coursegrp_portfolio') {
1746: # Needs to be in a course
1747: if (! ($env{'request.course.fn'})) {
1748: # Not in a course
1749: $env{'user.error.msg'}=
1750: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
1751: return HTTP_NOT_ACCEPTABLE;
1752: }
1753: my $earlyout = 0;
1.136 raeburn 1754: my $view_permission =
1755: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.137 albertel 1756: $env{'form.group'} =~ s/\W//g;
1.138 ! albertel 1757: $group = $env{'form.group'};
1.94 raeburn 1758: if ($group) {
1.138 ! albertel 1759: ($uname,$udom) = &get_name_dom();
1.99 raeburn 1760: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98 albertel 1761: $group);
1762: if (%curr_groups) {
1.132 raeburn 1763: my %grp_content = &Apache::longroup::get_group_settings(
1764: $curr_groups{$group});
1765: $grp_desc = &unescape($grp_content{'description'});
1.94 raeburn 1766: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
1767: $env{'request.course.id'}.'/'.$group))) {
1.138 ! albertel 1768: $portfolio_root = &get_portfolio_root();
1.94 raeburn 1769: } else {
1.116 albertel 1770: $r->print('You do not have the privileges required to access the shared files space for this group.');
1.94 raeburn 1771: $earlyout = 1;
1772: }
1773: } else {
1774: $r->print('Not a valid group for this course');
1775: $earlyout = 1;
1776: }
1777: $title = &mt('Group files').' for '.$group;
1778: } else {
1779: $r->print('Invalid group');
1780: $earlyout = 1;
1781: }
1782: if ($earlyout) { return OK; }
1.126 raeburn 1783: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
1.120 raeburn 1784: $can_modify = 1;
1785: $can_delete = 1;
1.126 raeburn 1786: $can_upload = 1;
1787: $can_setacl = 1;
1788: } else {
1789: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
1790: $can_setacl = 1;
1791: }
1792: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
1793: $can_upload = 1;
1794: }
1795: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
1796: $can_modify = 1;
1797: }
1798: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
1799: $can_delete = 1;
1800: }
1.120 raeburn 1801: }
1.94 raeburn 1802: } else {
1803: ($uname,$udom) = &get_name_dom();
1804: $portfolio_root = &get_portfolio_root();
1805: $title = &mt('Portfolio Manager');
1.120 raeburn 1806: $can_modify = 1;
1807: $can_delete = 1;
1808: $can_upload = 1;
1809: $can_setacl = 1;
1.94 raeburn 1810: }
1811:
1.138 ! albertel 1812: my $port_path = &get_port_path();
1.24 albertel 1813: &Apache::loncommon::no_cache($r);
1814: &Apache::loncommon::content_type($r,'text/html');
1815: $r->send_http_header;
1816: # Give the LON-CAPA page header
1.82 albertel 1817: if ($env{"form.mode"} eq 'selectfile'){
1.96 albertel 1818: $r->print(&Apache::loncommon::start_page($title,undef,
1.97 albertel 1819: {'only_body' => 1}));
1.108 raeburn 1820: } elsif ($env{'form.action'} eq 'rolepicker') {
1821: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
1822: {'no_nav_bar' => 1, }));
1.74 banghart 1823: } else {
1.97 albertel 1824: $r->print(&Apache::loncommon::start_page($title));
1.74 banghart 1825: }
1.24 albertel 1826: $r->rflush();
1.88 albertel 1827: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.116 albertel 1828: $r->print('<span class="LC_error">'.
1829: 'No file was selected to upload.'.
1830: 'To upload a file, click <strong>Browse...</strong>'.
1831: ', select a file, then click <strong>Upload</strong>.'.
1832: '</span>');
1.40 banghart 1833: }
1.82 albertel 1834: if ($env{'form.meta'}) {
1.94 raeburn 1835: &open_form($r,$url);
1.82 albertel 1836: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70 banghart 1837: $r->print('Edit the meta data<br />');
1.137 albertel 1838: &close_form($r,$url);
1.70 banghart 1839: }
1.82 albertel 1840: if ($env{'form.store'}) {
1.70 banghart 1841: }
1842:
1.82 albertel 1843: if ($env{'form.uploaddoc.filename'}) {
1.120 raeburn 1844: if ($can_upload) {
1.137 albertel 1845: &upload($r,$url,$group);
1.120 raeburn 1846: } else {
1.138 ! albertel 1847: &missing_priv($r,$url,'upload');
1.120 raeburn 1848: }
1.82 albertel 1849: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.120 raeburn 1850: if ($can_delete) {
1.138 ! albertel 1851: &delete_confirmed($r,$url);
1.120 raeburn 1852: } else {
1.138 ! albertel 1853: &missing_priv($r,$url,'delete');
1.120 raeburn 1854: }
1.82 albertel 1855: } elsif ($env{'form.action'} eq 'delete') {
1.120 raeburn 1856: if ($can_delete) {
1.138 ! albertel 1857: &delete($r,$url);
1.120 raeburn 1858: } else {
1.138 ! albertel 1859: &missing_priv($r,$url,'delete');
1.120 raeburn 1860: }
1.82 albertel 1861: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.120 raeburn 1862: if ($can_delete) {
1.138 ! albertel 1863: &delete_dir_confirmed($r,$url);
1.120 raeburn 1864: } else {
1.138 ! albertel 1865: &missing_priv($r,$url,'delete');
1.120 raeburn 1866: }
1867: } elsif ($env{'form.action'} eq 'deletedir') {
1868: if ($can_delete) {
1.137 albertel 1869: &delete_dir($r,$url);
1.120 raeburn 1870: } else {
1.138 ! albertel 1871: &missing_priv($r,$url,'delete');
1.120 raeburn 1872: }
1.82 albertel 1873: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.120 raeburn 1874: if ($can_modify) {
1.138 ! albertel 1875: &rename_confirmed($r,$url);
1.120 raeburn 1876: } else {
1.138 ! albertel 1877: &missing_priv($r,$url,'rename');
1.120 raeburn 1878: }
1.82 albertel 1879: } elsif ($env{'form.rename'}) {
1880: $env{'form.selectfile'} = $env{'form.rename'};
1881: $env{'form.action'} = 'rename';
1.120 raeburn 1882: if ($can_modify) {
1.138 ! albertel 1883: &rename($r,$url);
1.120 raeburn 1884: } else {
1.138 ! albertel 1885: &missing_priv($r,$url,'rename');
1.120 raeburn 1886: }
1.104 raeburn 1887: } elsif ($env{'form.access'}) {
1888: $env{'form.selectfile'} = $env{'form.access'};
1889: $env{'form.action'} = 'chgaccess';
1.137 albertel 1890: &display_access($r,$url,$group,$can_setacl,$port_path);
1.104 raeburn 1891: } elsif ($env{'form.action'} eq 'chgaccess') {
1.120 raeburn 1892: if ($can_setacl) {
1.137 albertel 1893: &update_access($r,$url,$group,$port_path);
1.120 raeburn 1894: } else {
1.138 ! albertel 1895: &missing_priv($r,$url,'setacl');
1.120 raeburn 1896: }
1.108 raeburn 1897: } elsif ($env{'form.action'} eq 'rolepicker') {
1.120 raeburn 1898: if ($can_setacl) {
1899: &role_options_window($r);
1900: } else {
1.138 ! albertel 1901: &missing_priv($r,$url,'setacl');
1.120 raeburn 1902: }
1.82 albertel 1903: } elsif ($env{'form.createdir'}) {
1.120 raeburn 1904: if ($can_upload) {
1.138 ! albertel 1905: &createdir($r,$url);
1.120 raeburn 1906: } else {
1.138 ! albertel 1907: &missing_priv($r,$url,'upload');
1.120 raeburn 1908: }
1.82 albertel 1909: } elsif ($env{'form.lockinfo'}) {
1.137 albertel 1910: &lock_info($r,$url,$group);
1.24 albertel 1911: } else {
1912: my $current_path='/';
1.82 albertel 1913: if ($env{'form.currentpath'}) {
1914: $current_path = $env{'form.currentpath'};
1.24 albertel 1915: }
1.132 raeburn 1916: if ($caller eq 'coursegrp_portfolio') {
1917: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.137 albertel 1918: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
1.132 raeburn 1919: }
1.138 ! albertel 1920: my @dir_list=&get_dir_list($portfolio_root);
1.46 albertel 1921: if ($dir_list[0] eq 'no_such_dir'){
1922: # two main reasons for this:
1923: # 1) never been here, so directory structure not created
1924: # 2) back-button navigation after deleting a directory
1925: if ($current_path eq '/'){
1.100 albertel 1926: &Apache::lonnet::mkdiruserfile($uname,$udom,
1.138 ! albertel 1927: &get_port_path());
1.46 albertel 1928: } else {
1929: # some directory that snuck in get rid of the directory
1930: # from the recent pulldown, just in case
1931: &Apache::lonhtmlcommon::remove_recent('portfolio',
1932: [$current_path]);
1933: $current_path = '/'; # force it back to the root
1934: }
1935: # now grab the directory list again, for the first time
1936: @dir_list=&Apache::lonnet::dirlist($current_path,
1.94 raeburn 1937: $udom,$uname,$portfolio_root);
1.43 banghart 1938: }
1.46 albertel 1939: # need to know if directory is empty so it can be removed if desired
1940: my $is_empty=(@dir_list == 2);
1.137 albertel 1941: &display_common($r,$url,$current_path,$is_empty,\@dir_list,
1942: $can_upload);
1.138 ! albertel 1943: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
1.137 albertel 1944: $can_upload,$can_modify,$can_delete,$can_setacl);
1.95 albertel 1945: $r->print(&Apache::loncommon::end_page());
1.30 banghart 1946: }
1.90 albertel 1947: return OK;
1.2 banghart 1948: }
1.120 raeburn 1949:
1.1 banghart 1950: 1;
1951: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>