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