Annotation of loncom/interface/portfolio.pm, revision 1.110
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);
1.109 albertel 542: my %access_controls =
543: &Apache::lonnet::get_access_controls($current_permissions,
544: $group,$file_name);
1.104 raeburn 545: if ($totalprocessed) {
546: if ($outcome eq 'ok') {
547: my $updated_controls = $access_controls{$file_name};
548: my ($showstart,$showend);
549: $r->print(&Apache::loncommon::start_data_table());
1.110 ! albertel 550: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 551: $r->print('<th>'.&mt('Type of change').'</th><th>'.
552: &mt('Access control').'</th><th>'.&mt('Dates available').
553: '</th><th>'.&mt('Additional information').'</th>');
1.110 ! albertel 554: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 555: foreach my $chg (sort(keys(%processing))) {
556: if (@{$processing{$chg}} > 0) {
557: if ($chg eq 'delete') {
558: if (!($deloutcome eq 'ok')) {
559: $errors .= &mt('A problem occurred deleting access controls: [_1]',$deloutcome);
560: next;
561: }
562: }
563: my $numchgs = @{$processing{$chg}};
564: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 565: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
566: '.</td>');
1.104 raeburn 567: my $count = 0;
568: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
569: if ($count) {
570: $r->print(&Apache::loncommon::start_data_table_row());
571: }
1.108 raeburn 572: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.104 raeburn 573: my $newkey = $key;
574: if ($chg eq 'activate') {
575: $newkey =~ s/^(\d+)/$$translation{$1}/;
576: }
1.109 albertel 577: my $content = $$updated_controls{$newkey};
1.104 raeburn 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') {
1.109 albertel 592: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 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') {
1.109 albertel 601: $r->print(&mt('Password').': '.$content->{'password'});
1.108 raeburn 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>');
1.109 albertel 614: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
1.108 raeburn 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;
1.109 albertel 622: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
1.108 raeburn 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 {
1.109 albertel 634: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
1.108 raeburn 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') {
1.109 albertel 642: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
1.108 raeburn 643: } elsif ($scope eq 'users') {
1.109 albertel 644: my $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 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) = @_;
1.109 albertel 704: my $record = {
705: type => $scope,
706: time => {
707: start => $start,
708: end => $end
709: },
710: };
711:
712: if ($scope eq 'guest') {
713: $record->{'password'} = $env{'form.password'};
1.108 raeburn 714: } elsif (($scope eq 'course') || ($scope eq 'group')) {
1.109 albertel 715: $record->{'domain'} = $env{'form.crsdom_'.$num};
716: $record->{'number'} = $env{'form.crsnum_'.$num};
1.108 raeburn 717: my @role_ids;
1.109 albertel 718: my @delete_role_ids =
719: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
720: my @preserves =
721: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
722: if (@delete_role_ids) {
723: foreach my $id (@preserves) {
724: if (grep {$_ = $id} (@delete_role_ids)) {
725: next;
726: }
727: push(@role_ids,$id);
728: }
729: } else {
730: push(@role_ids,@preserves);
731: }
732:
733: my $next_id = $env{'form.add_role_'.$num};
734: if ($next_id) {
735: push(@role_ids,$next_id);
736: }
737:
1.108 raeburn 738: foreach my $id (@role_ids) {
739: my (@roles,@accesses,@sections,@groups);
740: if (($id == $next_id) && ($chg eq 'update')) {
1.109 albertel 741: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1.108 raeburn 742: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
743: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1.109 albertel 744: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1.108 raeburn 745: } else {
746: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
747: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
748: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
749: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
750: }
1.109 albertel 751: $record->{'roles'}{$id}{'role'} = \@roles;
752: $record->{'roles'}{$id}{'access'} = \@accesses;
753: $record->{'roles'}{$id}{'section'} = \@sections;
754: $record->{'roles'}{$id}{'group'} = \@groups;
1.108 raeburn 755: }
756: } elsif ($scope eq 'domains') {
757: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1.109 albertel 758: $record->{'dom'} = \@doms;
1.108 raeburn 759: } elsif ($scope eq 'users') {
760: my $userlist = $env{'form.users_'.$num};
1.109 albertel 761: $userlist =~ s/\s+//sg;
762: my %userhash = map { ($_,1) } (split(/,/,$userlist));
763: foreach my $user (keys(%userhash)) {
1.108 raeburn 764: my ($uname,$udom) = split(/:/,$user);
1.109 albertel 765: push(@{$record->{'users'}}, {
766: 'uname' => $uname,
767: 'udom' => $udom
768: });
769: }
1.108 raeburn 770: }
1.104 raeburn 771: return $record;
772: }
773:
774: sub get_dates_from_form {
775: my ($id) = @_;
776: my $startdate;
777: my $enddate;
778: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
779: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
780: if ( exists ($env{'form.noend_'.$id}) ) {
781: $enddate = 0;
782: }
783: return ($startdate,$enddate);
784: }
785:
1.108 raeburn 786: sub sort_users {
1.109 albertel 787: my ($users) = @_;
788: my @curr_users = map {
789: $_->{'uname'}.':'.$_->{'udom'}
790: } (@{$users});
791: my $curr_user_list = join(",\n",sort(@curr_users));
1.108 raeburn 792: return $curr_user_list;
793: }
794:
1.104 raeburn 795: sub access_setting_table {
796: my ($r,$access_controls) = @_;
797: my ($public,$publictext);
1.108 raeburn 798: $publictext = &mt('Off');
1.104 raeburn 799: my ($guest,$guesttext);
1.108 raeburn 800: $guesttext = &mt('Off');
1.104 raeburn 801: my @courses = ();
802: my @groups = ();
803: my @domains = ();
804: my @users = ();
805: my $now = time;
806: my $then = $now + (60*60*24*180); # six months approx.
1.108 raeburn 807: my ($num,$scope,$publicnum,$guestnum);
808: my (%acl_count,%end,%start);
1.104 raeburn 809: foreach my $key (sort(keys(%{$access_controls}))) {
1.108 raeburn 810: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1.104 raeburn 811: if ($scope eq 'public') {
812: $public = $key;
1.108 raeburn 813: $publicnum = $num;
814: $publictext = &acl_status($start{$key},$end{$key},$now);
815: } elsif ($scope eq 'guest') {
816: $guest=$key;
817: $guestnum = $num;
818: $guesttext = &acl_status($start{$key},$end{$key},$now);
819: } elsif ($scope eq 'course') {
820: push(@courses,$key);
821: } elsif ($scope eq 'group') {
822: push(@groups,$key);
823: } elsif ($scope eq 'domains') {
824: push(@domains,$key);
825: } elsif ($scope eq 'users') {
826: push(@users,$key);
1.104 raeburn 827: }
1.108 raeburn 828: $acl_count{$scope} ++;
1.104 raeburn 829: }
1.108 raeburn 830: $r->print('<table border="0"><tr><td valign="top">');
831: $r->print('<h3>'.&mt('Public access:').' '.$publictext.'</h3>');
1.104 raeburn 832: $r->print(&Apache::loncommon::start_data_table());
1.110 ! albertel 833: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 834: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1.110 ! albertel 835: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 836: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 837: if ($public) {
838: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
839: &dateboxes($publicnum,$start{$public},$end{$public}).'</td>');
840: } else {
841: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
842: &dateboxes('0',$now,$then).'</td>');
843: }
844: $r->print(&Apache::loncommon::end_data_table_row());
845: $r->print(&Apache::loncommon::end_data_table());
846: $r->print('</td><td width="40"> </td><td valign="top">');
847: $r->print('<h3>'.&mt('Password-protected access:').' '.$guesttext.'</h3>');
1.104 raeburn 848: $r->print(&Apache::loncommon::start_data_table());
1.110 ! albertel 849: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 850: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
851: '</th><th>'. &mt('Password').'</th>');
1.110 ! albertel 852: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 853: $r->print(&Apache::loncommon::start_data_table_row());
854: my $passwd;
855: if ($guest) {
1.109 albertel 856: $passwd = $$access_controls{$guest}{'password'};
1.108 raeburn 857: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
858: &dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
859: } else {
860: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
861: &dateboxes('1',$now,$then).'</td>');
1.104 raeburn 862: }
1.108 raeburn 863: $r->print('<td><input type="text" size="15" name="password" value="'.
864: $passwd.'" /></td>');
1.104 raeburn 865: $r->print(&Apache::loncommon::end_data_table_row());
866: $r->print(&Apache::loncommon::end_data_table());
1.108 raeburn 867: $r->print('</td></tr><tr><td colspan="3"> </td></tr><tr><td valign="top">');
868: &access_element($r,'domains',\%acl_count,\@domains,$access_controls,$now,$then);
869: $r->print('</td><td> </td><td valign="top">');
870: &access_element($r,'users',\%acl_count,\@users,$access_controls,$now,$then);
871: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
872: if (@courses > 0 || @groups > 0) {
873: $r->print('<td colspan="3" valign="top">');
874: } else {
875: $r->print('<td valign="top">');
876: }
877: &access_element($r,'course',\%acl_count,\@courses,$access_controls,$now,$then);
1.104 raeburn 878: $r->print('</td>');
1.108 raeburn 879: if (@courses > 0 || @groups > 0) {
880: $r->print('</tr><tr><td colspan="3"> </td></tr><tr><td colspan="3" valign="top">');
881: } else {
882: $r->print('<td> </td><td valign="top">');
883: }
884: &access_element($r,'group',\%acl_count,\@groups,$access_controls,$now,$then);
885: $r->print('</td></tr></table>');
886: }
887:
888: sub acl_status {
889: my ($start,$end,$now) = @_;
890: if ($start > $now) {
891: return &mt('Inactive');
892: }
893: if ($end && $end<$now) {
894: return &mt('Inactive');
895: }
896: return &mt('Active');
897: }
898:
899: sub access_element {
900: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
901: my $title = $type;
902: $title =~ s/s$//;
903: $title =~ s/^(\w)/uc($1)/e;
904: $r->print('<h3>'.&mt('[_1]-based conditional access: ',$title));
905: if ($$acl_count{$type}) {
906: $r->print($$acl_count{$type}.' ');
907: if ($$acl_count{$type} > 1) {
908: $r->print(&mt('conditions'));
909: } else {
910: $r->print(&mt('condition'));
911: }
912: } else {
913: $r->print(&mt('Off'));
914: }
915: $r->print('</h3>');
916: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
917: return;
918: }
919:
920: sub display_access_row {
921: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
922: if (@{$items} > 0) {
923: my @all_doms;
924: my $tablecolor;
925: my $colspan = 3;
926: my $uctype = $type;
927: $uctype =~ s/^(\w)/uc($1)/e;
928: $r->print(&Apache::loncommon::start_data_table());
1.110 ! albertel 929: $r->print(&Apache::loncommon::start_data_table_header_row());
! 930: $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
1.108 raeburn 931: &mt('Dates available').'</th>');
932: if (($type eq 'course') || ($type eq 'group')) {
933: $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
934: '</th>');
935: $colspan ++;
936: my $function = &Apache::loncommon::get_users_function();
937: $tablecolor=&Apache::loncommon::designparm($function.'.tabbg');
938: } elsif ($type eq 'domains') {
939: @all_doms = &Apache::loncommon::get_domains();
940: }
1.110 ! albertel 941: $r->print(&Apache::loncommon::end_data_table_header_row());
! 942: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 943: foreach my $key (@{$items}) {
944: if (($type eq 'course') || ($type eq 'group')) {
945: &course_row($r,$status,$type,$key,$access_controls,
946: $tablecolor,$now,$then);
947: } elsif ($type eq 'domains') {
948: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
949: $then);
950: } elsif ($type eq 'users') {
951: &users_row($r,$status,$key,$access_controls,$now,$then);
952: }
953: }
954: $r->print(&Apache::loncommon::end_data_table_row());
955: $r->print(&Apache::loncommon::start_data_table_row());
956: if ($status eq 'old') {
957: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
958: '</td>');
959: }
1.110 ! albertel 960: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 961: $r->print(&Apache::loncommon::end_data_table());
962: } else {
963: $r->print(&mt('No [_1]-based conditions defined.<br />',$type).
964: &additional_item($type));
965: }
966: return;
967: }
968:
1.110 ! albertel 969: sub course_js {
! 970: return qq|
1.108 raeburn 971: <script type="text/javascript">
972: function setRoleOptions(caller,num,cdom,cnum,type) {
973: addIndexnum = getCallerIndex(caller);
974: updateIndexnum = getIndex('update',num);
975: if (caller.checked) {
976: document.portform.elements[updateIndexnum].checked = true;
977: var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
978: var title = 'Roles_Chooser';
979: var options = 'scrollbars=1,resizable=1,menubar=0';
980: options += ',width=700,height=600';
981: rolebrowser = open(url,title,options,'1');
982: rolebrowser.focus();
983: } else {
984: for (var j=0;j<5;j++) {
985: document.portform.elements[addIndexnum+j].value = '';
986: }
987: }
988: }
989:
990: function getCallerIndex(caller) {
991: for (var i=0;i<document.portform.elements.length;i++) {
992: if (document.portform.elements[i] == caller) {
993: return i;
994: }
995: }
996: return -1;
997: }
998:
999: function getIndex(name,value) {
1000: for (var i=0;i<document.portform.elements.length;i++) {
1001: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1002: return i;
1003: }
1004: }
1005: return -1;
1006: }
1007:
1008: </script>
1.110 ! albertel 1009: |;
! 1010: }
! 1011:
! 1012: sub course_row {
! 1013: my ($r,$status,$type,$item,$access_controls,$tablecolor,$now,$then) = @_;
! 1014: my %content;
! 1015: my $defdom = $env{'user.domain'};
! 1016: if ($status eq 'old') {
! 1017: $defdom = $$access_controls{$item}{'domain'};
! 1018: }
! 1019: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
! 1020: .&course_js();
1.108 raeburn 1021: my $crsgrptext = 'Groups';
1022: if ($type eq 'group') {
1023: $crsgrptext = 'Teams';
1024: }
1025: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1026: $type);
1.110 ! albertel 1027: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1.108 raeburn 1028: if ($status eq 'old') {
1029: my $cid = $content{'domain'}.'_'.$content{'number'};
1030: my %course_description = &Apache::lonnet::coursedescription($cid);
1031: $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>');
1032: } elsif ($status eq 'new') {
1033: my $uctype = $type;
1034: $uctype =~ s/^(\w)/uc($1)/e;
1035: $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>');
1036: }
1037: $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
1038: $r->print('<td><table border="0"><tr bgcolor="'.$tablecolor.'">');
1039: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
1040: &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
1041: &mt($crsgrptext).'</th></tr>');
1042: if ($status eq 'old') {
1043: my $max_id = 0;
1044: foreach my $role_id (sort(keys(%{$content{'roles'}}))) {
1045: if ($role_id > $max_id) {
1046: $max_id = $role_id;
1047: }
1048: $max_id ++;
1049: my $role_selects = &role_selectors($num,$role_id,$status,$type,\%content,'display');
1050: $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>');
1051: }
1052: $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>');
1053: } elsif ($status eq 'new') {
1054: my $role_id = 1;
1055: my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
1056: $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);
1057: $r->print('</tr></table></td>');
1058: }
1059: return;
1060: }
1061:
1062: sub domains_row {
1063: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1064: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1065: 'domains');
1066: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true"/>'.
1067: ' <option value="">'.&mt('Please select').'</option>';
1068: if ($status eq 'old') {
1.109 albertel 1069: my $content = $$access_controls{$item};
1070: foreach my $dom (@{$all_doms}) {
1071: if ((@{$content->{'dom'}} > 0)
1072: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.108 raeburn 1073: $dom_select .= '<option value="'.$dom.'" selected>'.
1074: $dom.'</option>';
1075: } else {
1076: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1077: }
1078: }
1079: } else {
1080: foreach my $dom (@{$all_doms}) {
1081: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1082: }
1083: }
1084: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1085: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1086: }
1087:
1088: sub users_row {
1089: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1090: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1091: 'users');
1092: my $curr_user_list;
1093: if ($status eq 'old') {
1.109 albertel 1094: my $content = $$access_controls{$item};
1095: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1096: }
1097: $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>');
1098: }
1099:
1100: sub additional_item {
1101: my ($type) = @_;
1102: my $output = &mt('Add new [_1] condition(s)?',$type).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1103: return $output;
1104: }
1105:
1106: sub actionbox {
1107: my ($status,$num,$scope) = @_;
1108: my $output = '<nobr><label>';
1109: if ($status eq 'new') {
1110: $output .= '<input type="checkbox" name="activate" value="'.$num.'" />'.
1111: &mt('Activate');
1112: } else {
1113: $output .= '<input type="checkbox" name="delete" value="'.$num.
1114: '" />'.&mt('Delete').'</label><br /><nobr>'.
1115: '<label><input type="checkbox" name="update" value="'.
1116: $num.'" />'.&mt('Update');
1117: }
1118: $output .= '</label></nobr><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1119: return $output;
1120: }
1121:
1122: sub dateboxes {
1123: my ($num,$start,$end) = @_;
1124: my $noend;
1125: if ($end == 0) {
1126: $noend = 'checked="checked"';
1127: }
1128: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1129: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1130: undef,undef,1);
1131: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1132: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1133: undef,undef,1). ' <nobr><label>'.
1134: '<input type="checkbox" name="noend_'.
1135: $num.'" '.$noend.' />'.&mt('No end date').
1136: '</label></nobr>';
1137:
1138: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1139: return $output;
1140: }
1141:
1142: sub unpack_acc_key {
1143: my ($acc_key) = @_;
1144: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1145: return ($num,$scope,$end,$start);
1146: }
1147:
1148: sub set_identifiers {
1149: my ($status,$item,$now,$then,$scope) = @_;
1150: if ($status eq 'old') {
1151: return(&unpack_acc_key($item));
1152: } else {
1153: return($item,$scope,$then,$now);
1154: }
1155: }
1156:
1157: sub role_selectors {
1158: my ($num,$role_id,$status,$type,$content,$caller) = @_;
1159: my ($output,$cdom,$cnum,$longid);
1160: if ($caller eq 'display') {
1161: $longid = '_'.$num.'_'.$role_id;
1162: if ($status eq 'new') {
1163: foreach my $item ('role','access','section','group') {
1164: $output .= '<td><select name="'.$item.$longid.'">'.
1165: '<option value="">'.&mt('Pick [_1] first',$type).
1166: '</option></select></td>';
1167: }
1168: return $output;
1169: } else {
1170: $cdom = $$content{'domain'};
1171: $cnum = $$content{'number'};
1172: }
1173: } elsif ($caller eq 'rolepicker') {
1174: $cdom = $env{'form.cdom'};
1175: $cnum = $env{'form.cnum'};
1176: }
1177: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1178: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$type);
1179: if (!@{$sections}) {
1180: @{$sections} = ('none');
1181: } else {
1182: unshift(@{$sections},('all','none'));
1183: }
1184: if (!@{$groups}) {
1185: @{$groups} = ('none');
1186: } else {
1187: unshift(@{$groups},('all','none'));
1188: }
1189: my @allacesses = sort(keys(%{$accesshash}));
1190: my (%sectionhash,%grouphash);
1191: foreach my $sec (@{$sections}) {
1192: $sectionhash{$sec} = $sec;
1193: }
1194: foreach my $grp (@{$groups}) {
1195: $grouphash{$grp} = $grp;
1196: }
1197: my %lookup = (
1198: 'role' => $rolehash,
1199: 'access' => $accesshash,
1200: 'section' => \%sectionhash,
1201: 'group' => \%grouphash,
1202: );
1203: my @allaccesses = sort(keys(%{$accesshash}));
1204: my %allitems = (
1205: 'role' => $allroles,
1206: 'access' => \@allaccesses,
1207: 'section' => $sections,
1208: 'group' => $groups,
1209: );
1210: foreach my $item ('role','access','section','group') {
1211: $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
1212: foreach my $entry (@{$allitems{$item}}) {
1213: if ($caller eq 'display') {
1214: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1215: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1216: $output .= ' <option value="'.$entry.'" selected>'.
1217: $lookup{$item}{$entry}.'</option>';
1218: next;
1219: }
1220: }
1221: $output .= ' <option value="'.$entry.'">'.
1222: $lookup{$item}{$entry}.'</option>';
1223: }
1224: $output .= '</select>';
1225: }
1226: $output .= '</td>';
1227: return $output;
1228: }
1229:
1230: sub role_options_window {
1231: my ($r) = @_;
1232: my $cdom = $env{'form.cdom'};
1233: my $cnum = $env{'form.cnum'};
1234: my $type = $env{'form.type'};
1235: my $addindex = $env{'form.setroles'};
1236: my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker');
1237: $r->print(<<"END_SCRIPT");
1238: <script type="text/javascript">
1239: function setRoles() {
1240: var addidx = $addindex+1;
1241: for (var i=0; i<4; i++) {
1242: var copylist = '';
1243: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1244: if (document.rolepicker.elements[i].options[j].selected) {
1245: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1246: }
1247: }
1248: copylist = copylist.substr(0,copylist.length-1);
1249: opener.document.portform.elements[addidx+i].value = copylist;
1250: }
1251: self.close();
1252: }
1253: </script>
1254: END_SCRIPT
1255: $r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
1256: $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()" />');
1257: return;
1.104 raeburn 1258: }
1259:
1.47 banghart 1260: sub select_files {
1.104 raeburn 1261: my ($r,$group) = @_;
1.82 albertel 1262: if ($env{'form.continue'} eq 'true') {
1.60 banghart 1263: # here we update the selections for the currentpath
1264: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 1265: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1266: if (scalar(@items)){
1.85 banghart 1267: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 1268: }
1.62 banghart 1269: } else {
1270: #empty the file for a fresh start
1.83 banghart 1271: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 1272: }
1.82 albertel 1273: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 1274: my $java_files = join ",", @files;
1275: if ($java_files) {
1276: $java_files.=',';
1.60 banghart 1277: }
1.63 banghart 1278: my $javascript =(<<ENDSMP);
1.48 banghart 1279: <script language='javascript'>
1280: function finishSelect() {
1.62 banghart 1281: ENDSMP
1.63 banghart 1282: $javascript .= 'fileList = "'.$java_files.'";';
1283: $javascript .= (<<ENDSMP);
1.49 banghart 1284: for (i=0;i<document.forms.checkselect.length;i++) {
1285: if (document.forms.checkselect[i].checked){
1.54 banghart 1286: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 1287: }
1288: }
1289: opener.document.forms.lonhomework.
1290: ENDSMP
1.82 albertel 1291: $javascript .= $env{'form.fieldname'};
1.63 banghart 1292: $javascript .= (<<ENDSMP);
1.49 banghart 1293: .value=fileList;
1.48 banghart 1294: self.close();
1295: }
1296: </script>
1297: ENDSMP
1.63 banghart 1298: $r->print($javascript);
1.47 banghart 1299: $r->print("<h1>Select portfolio files</h1>
1.88 albertel 1300: Check as many as you wish in response to the problem.<br />");
1301: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1302: if (@otherfiles) {
1303: $r->print("<strong>Files selected from other directories:</strong><br />");
1304: foreach my $file (@otherfiles) {
1305: $r->print($file."<br />");
1306: }
1.60 banghart 1307: }
1.47 banghart 1308: }
1.24 albertel 1309: sub upload {
1.94 raeburn 1310: my ($r,$url,$group)=@_;
1.82 albertel 1311: my $fname=$env{'form.uploaddoc.filename'};
1312: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.38 banghart 1313: my $disk_quota = 20000; # expressed in k
1.34 banghart 1314: $fname=&Apache::lonnet::clean_filename($fname);
1.94 raeburn 1315:
1316: my $portfolio_root=&get_portfolio_root($group);
1317: my ($uname,$udom) = &get_name_dom($group);
1318: my $port_path = &get_port_path($group);
1.38 banghart 1319: # Fixme --- Move the checking for existing file to LOND error return
1.94 raeburn 1320: my @dir_list=&get_dir_list($portfolio_root,$group);
1.34 banghart 1321: my $found_file = 0;
1.76 banghart 1322: my $locked_file = 0;
1.33 banghart 1323: foreach my $line (@dir_list) {
1.76 banghart 1324: my ($file_name)=split(/\&/,$line,2);
1325: if ($file_name eq $fname){
1.102 raeburn 1326: $file_name = $env{'form.currentpath'}.$file_name;
1327: $file_name = &prepend_group($file_name,$group);
1.33 banghart 1328: $found_file = 1;
1.102 raeburn 1329: if (defined($group)) {
1330: $file_name = $group.'/'.$file_name;
1331: }
1332: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.76 banghart 1333: $locked_file = 1;
1334: }
1.33 banghart 1335: }
1336: }
1.94 raeburn 1337: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
1.87 albertel 1338: if (($current_disk_usage + $filesize) > $disk_quota){
1.86 albertel 1339: $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.'.
1.38 banghart 1340: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.94 raeburn 1341: $r->print(&done('Back',$url,$group));
1.38 banghart 1342: }
1.76 banghart 1343: elsif ($found_file){
1344: if ($locked_file){
1.94 raeburn 1345: $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 1346: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
1.94 raeburn 1347: $r->print(&done('Back',$url,$group));
1.76 banghart 1348: } else {
1.94 raeburn 1349: $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>'.
1350: '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
1351: $r->print(&done('Back',$url,$group));
1.76 banghart 1352: }
1.33 banghart 1353: } else {
1354: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.94 raeburn 1355: $port_path.$env{'form.currentpath'});
1.33 banghart 1356: if ($result !~ m|^/uploaded/|) {
1.34 banghart 1357: $r->print('<font color="red"> An errror occured ('.$result.
1358: ') while trying to upload '.&display_file().'</font><br />');
1.94 raeburn 1359: $r->print(&done('Back',$url,$group));
1.76 banghart 1360: } else {
1.94 raeburn 1361: $r->print(&done(undef,$url,$group));
1.33 banghart 1362: }
1.25 albertel 1363: }
1364: }
1.80 banghart 1365: sub lock_info {
1.94 raeburn 1366: my ($r,$url,$group) = @_;
1367: my ($uname,$udom) = &get_name_dom($group);
1.102 raeburn 1368: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1369: $uname);
1.84 banghart 1370: my $file_name = $env{'form.lockinfo'};
1.102 raeburn 1371: $file_name = &prepend_group($file_name,$group);
1372: if (defined($file_name) && defined($$current_permissions{$file_name})) {
1373: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1374: if (ref($array_item) eq 'ARRAY') {
1375: my $filetext;
1376: if (defined($group)) {
1377: $filetext = '<strong>'.$env{'form.lockinfo'}.
1378: '</strong> (group: '.$group.')';
1379: } else {
1380: $filetext = '<strong>'.$file_name.'</strong>';
1381: }
1382: $r->print(&mt('[_1] was submitted in response to problem: ',
1383: $filetext).
1384: '<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
1385: '</strong><br />');
1386: my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
1387: $r->print(&mt('In the course: <strong>[_1]</strong><br />',
1388: $course_description{'description'}));
1389: # $r->print('the third is '.$$array_item[2].'<br>');
1390: # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
1.85 banghart 1391: }
1.102 raeburn 1392: }
1.84 banghart 1393: }
1.94 raeburn 1394: $r->print(&done('Back',$url,$group));
1.80 banghart 1395: return 'ok';
1396: }
1.25 albertel 1397: sub createdir {
1.94 raeburn 1398: my ($r,$url,$group)=@_;
1.82 albertel 1399: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 1400: if ($newdir eq '') {
1.37 banghart 1401: $r->print('<font color="red">'.
1402: &mt("Error: no directory name was provided.").
1403: '</font><br />');
1.94 raeburn 1404: $r->print(&done(undef,$url,$group));
1.37 banghart 1405: return;
1.94 raeburn 1406: }
1407: my $portfolio_root = &get_portfolio_root($group);
1408: my @dir_list=&get_dir_list($portfolio_root,$group);
1.37 banghart 1409: my $found_file = 0;
1410: foreach my $line (@dir_list) {
1411: my ($filename)=split(/\&/,$line,2);
1412: if ($filename eq $newdir){
1413: $found_file = 1;
1414: }
1415: }
1416: if ($found_file){
1417: $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
1418: ' </strong>a file or directory by that name already exists.</font><br />');
1419: } else {
1.94 raeburn 1420: my ($uname,$udom) = &get_name_dom($group);
1421: my $port_path = &get_port_path($group);
1422: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
1423: $port_path.$env{'form.currentpath'}.$newdir);
1.37 banghart 1424: if ($result ne 'ok') {
1425: $r->print('<font color="red"> An errror occured ('.$result.
1426: ') while trying to create a new directory '.&display_file().'</font><br />');
1427: }
1.24 albertel 1428: }
1.82 albertel 1429: if ($newdir ne $env{'form.newdir'}) {
1430: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1.67 banghart 1431: }
1.94 raeburn 1432: $r->print(&done(undef,$url,$group));
1433: }
1434:
1435: sub get_portfolio_root {
1436: my ($group) = @_;
1437: my ($portfolio_root,$udom,$uname,$path);
1438: ($uname,$udom) = &get_name_dom($group);
1439: if (defined($group)) {
1440: $path = '/userfiles/groups/'.$group.'/portfolio';
1441: } else {
1442: $path = '/userfiles/portfolio';
1443: }
1444: return (&Apache::loncommon::propath($udom,$uname).$path);
1445: }
1446:
1447: sub get_dir_list {
1448: my ($portfolio_root,$group) = @_;
1449: my ($uname,$udom) = &get_name_dom($group);
1450: return &Apache::lonnet::dirlist($env{'form.currentpath'},
1451: $udom,$uname,$portfolio_root);
1452: }
1453:
1454: sub get_name_dom {
1455: my ($group) = @_;
1456: my ($uname,$udom);
1457: if (defined($group)) {
1458: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1459: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
1460: } else {
1461: $udom = $env{'user.domain'};
1462: $uname = $env{'user.name'};
1463: }
1464: return ($uname,$udom);
1465: }
1466:
1.102 raeburn 1467: sub prepend_group {
1468: my ($filename,$group) = @_;
1469: if (defined($group)) {
1470: $filename = $group.'/'.$filename;
1471: }
1472: return $filename;
1473: }
1474:
1.94 raeburn 1475: sub get_namespace {
1476: my ($group) = @_;
1477: my $namespace = 'portfolio';
1478: if (defined($group)) {
1479: my ($uname,$udom) = &get_name_dom($group);
1480: $namespace .= '_'.$udom.'_'.$uname.'_'.$group;
1481: }
1482: return $namespace;
1483: }
1484:
1485: sub get_port_path {
1486: my ($group) = @_;
1487: my $port_path;
1488: if (defined($group)) {
1489: $port_path = "groups/$group/portfolio";
1490: } else {
1491: $port_path = 'portfolio';
1492: }
1493: return $port_path;
1.24 albertel 1494: }
1495:
1496: sub handler {
1497: # this handles file management
1498: my $r = shift;
1.73 banghart 1499: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.108 raeburn 1500: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
1501: 'fieldname','mode','rename','continue','group','access','setnum',
1502: 'cnum','cdom','type','setroles']);
1.94 raeburn 1503: my ($uname,$udom,$portfolio_root,$url,$group,$caller,$title);
1504: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
1505: $url = $1.$2;
1506: $caller = $2;
1507: }
1508: if ($caller eq 'coursegrp_portfolio') {
1509: # Needs to be in a course
1510: if (! ($env{'request.course.fn'})) {
1511: # Not in a course
1512: $env{'user.error.msg'}=
1513: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
1514: return HTTP_NOT_ACCEPTABLE;
1515: }
1516: my $earlyout = 0;
1517: my $view_permission = &Apache::lonnet::allowed('vcg',
1518: $env{'request.course.id'});
1519: $group = $env{'form.group'};
1520: $group =~ s/\W//g;
1521: if ($group) {
1522: ($uname,$udom) = &get_name_dom($group);
1.99 raeburn 1523: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98 albertel 1524: $group);
1525: if (%curr_groups) {
1.94 raeburn 1526: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
1527: $env{'request.course.id'}.'/'.$group))) {
1528: $portfolio_root = &get_portfolio_root($group);
1529: } else {
1530: $r->print('You do not have the privileges required to access the shared files space for this group');
1531: $earlyout = 1;
1532: }
1533: } else {
1534: $r->print('Not a valid group for this course');
1535: $earlyout = 1;
1536: }
1537: $title = &mt('Group files').' for '.$group;
1538: } else {
1539: $r->print('Invalid group');
1540: $earlyout = 1;
1541: }
1542: if ($earlyout) { return OK; }
1543: } else {
1544: ($uname,$udom) = &get_name_dom();
1545: $portfolio_root = &get_portfolio_root();
1546: $title = &mt('Portfolio Manager');
1547: }
1548:
1.24 albertel 1549: &Apache::loncommon::no_cache($r);
1550: &Apache::loncommon::content_type($r,'text/html');
1551: $r->send_http_header;
1552: # Give the LON-CAPA page header
1.82 albertel 1553: if ($env{"form.mode"} eq 'selectfile'){
1.96 albertel 1554: $r->print(&Apache::loncommon::start_page($title,undef,
1.97 albertel 1555: {'only_body' => 1}));
1.108 raeburn 1556: } elsif ($env{'form.action'} eq 'rolepicker') {
1557: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
1558: {'no_nav_bar' => 1, }));
1.74 banghart 1559: } else {
1.97 albertel 1560: $r->print(&Apache::loncommon::start_page($title));
1.74 banghart 1561: }
1.24 albertel 1562: $r->rflush();
1.88 albertel 1563: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.40 banghart 1564: $r->print('<font color="red"> No file was selected to upload.'.
1565: 'To upload a file, click <strong>Browse...</strong>'.
1566: ', select a file, then click <strong>Upload</strong>,</font>');
1567: }
1.82 albertel 1568: if ($env{'form.meta'}) {
1.94 raeburn 1569: &open_form($r,$url);
1.82 albertel 1570: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70 banghart 1571: $r->print('Edit the meta data<br />');
1.94 raeburn 1572: &close_form($r,$url,$group);
1.70 banghart 1573: }
1.82 albertel 1574: if ($env{'form.store'}) {
1.70 banghart 1575: }
1576:
1.82 albertel 1577: if ($env{'form.uploaddoc.filename'}) {
1.94 raeburn 1578: &upload($r,$url,$group);
1.82 albertel 1579: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.94 raeburn 1580: &delete_confirmed($r,$url,$group);
1.82 albertel 1581: } elsif ($env{'form.action'} eq 'delete') {
1.94 raeburn 1582: &delete($r,$url,$group);
1.82 albertel 1583: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.94 raeburn 1584: &delete_dir_confirmed($r,$url,$group);
1.82 albertel 1585: } elsif ($env{'form.action'} eq 'deletedir'){
1.94 raeburn 1586: &delete_dir($r,$url,$group);
1.82 albertel 1587: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.94 raeburn 1588: &rename_confirmed($r,$url,$group);
1.82 albertel 1589: } elsif ($env{'form.rename'}) {
1590: $env{'form.selectfile'} = $env{'form.rename'};
1591: $env{'form.action'} = 'rename';
1.94 raeburn 1592: &rename($r,$url,$group);
1.104 raeburn 1593: } elsif ($env{'form.access'}) {
1594: $env{'form.selectfile'} = $env{'form.access'};
1595: $env{'form.action'} = 'chgaccess';
1596: &display_access($r,$url,$group);
1597: } elsif ($env{'form.action'} eq 'chgaccess') {
1598: &update_access($r,$url,$group);
1.108 raeburn 1599: } elsif ($env{'form.action'} eq 'rolepicker') {
1600: &role_options_window($r);
1.82 albertel 1601: } elsif ($env{'form.createdir'}) {
1.94 raeburn 1602: &createdir($r,$url,$group);
1.82 albertel 1603: } elsif ($env{'form.lockinfo'}) {
1.94 raeburn 1604: &lock_info($r,$url,$group);
1.24 albertel 1605: } else {
1606: my $current_path='/';
1.82 albertel 1607: if ($env{'form.currentpath'}) {
1608: $current_path = $env{'form.currentpath'};
1.24 albertel 1609: }
1.94 raeburn 1610: my @dir_list=&get_dir_list($portfolio_root,$group);
1.46 albertel 1611: if ($dir_list[0] eq 'no_such_dir'){
1612: # two main reasons for this:
1613: # 1) never been here, so directory structure not created
1614: # 2) back-button navigation after deleting a directory
1615: if ($current_path eq '/'){
1.100 albertel 1616: &Apache::lonnet::mkdiruserfile($uname,$udom,
1617: &get_port_path($group));
1.46 albertel 1618: } else {
1619: # some directory that snuck in get rid of the directory
1620: # from the recent pulldown, just in case
1621: &Apache::lonhtmlcommon::remove_recent('portfolio',
1622: [$current_path]);
1623: $current_path = '/'; # force it back to the root
1624: }
1625: # now grab the directory list again, for the first time
1626: @dir_list=&Apache::lonnet::dirlist($current_path,
1.94 raeburn 1627: $udom,$uname,$portfolio_root);
1.43 banghart 1628: }
1.46 albertel 1629: # need to know if directory is empty so it can be removed if desired
1630: my $is_empty=(@dir_list == 2);
1.94 raeburn 1631: &display_common($r,$url,$current_path,$is_empty,\@dir_list,$group);
1632: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group);
1.95 albertel 1633: $r->print(&Apache::loncommon::end_page());
1.30 banghart 1634: }
1.90 albertel 1635: return OK;
1.2 banghart 1636: }
1.1 banghart 1637: 1;
1638: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>