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