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