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