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