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