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