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