1: # The LearningOnline Network
2: # portfolio browser
3: #
4: # $Id: portfolio.pm,v 1.156.2.1 2006/08/14 21:35:04 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 or passphrase-protected.');
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.');
645: $info .= '</li></ul>';
646: if ($group eq '') {
647: $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>"));
648: }
649:
650: if ($can_setacl) {
651: &open_form($r,$url);
652: $r->print($header.$info);
653: &access_setting_table($r,$access_controls{$file_name});
654: my $button_text = {
655: 'continue' => &mt('Proceed'),
656: 'cancel' => &mt('Back to directory listing'),
657: };
658: &close_form($r,$url,$button_text);
659: } else {
660: $r->print($header);
661: if ($aclcount) {
662: $r->print($info);
663: }
664: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
665: }
666: }
667:
668: sub view_access_settings {
669: my ($r,$url,$access_controls,$aclcount) = @_;
670: my ($showstart,$showend);
671: my %todisplay;
672: foreach my $key (sort(keys(%{$access_controls}))) {
673: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
674: $todisplay{$scope}{$key} = $$access_controls{$key};
675: }
676: if ($aclcount) {
677: $r->print(&mt('<h4>Current access controls defined for this file:</h4>'));
678: $r->print(&Apache::loncommon::start_data_table());
679: $r->print(&Apache::loncommon::start_data_table_header_row());
680: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
681: '</th><th>'.&mt('Additional information').'</th>');
682: $r->print(&Apache::loncommon::end_data_table_header_row());
683: my $count = 1;
684: my $chg = 'none';
685: &build_access_summary($r,$count,$chg,%todisplay);
686: $r->print(&Apache::loncommon::end_data_table());
687: } else {
688: $r->print(&mt('No access control settings currently exist for this file.<br />' ));
689: }
690: my %anchor_fields = (
691: 'currentpath' => $env{'form.currentpath'}
692: );
693: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory listing')));
694: return;
695: }
696:
697: sub build_access_summary {
698: my ($r,$count,$chg,%todisplay) = @_;
699: my ($showstart,$showend);
700: my %scope_desc = (
701: public => 'Public',
702: guest => 'Passphrase-protected',
703: domains => 'Conditional: domain-based',
704: users => 'Conditional: user-based',
705: course => 'Conditional: course-based',
706: group => 'Conditional: group-based',
707: );
708: my @allscopes = ('public','guest','domains','users','course','group');
709: foreach my $scope (@allscopes) {
710: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
711: next;
712: }
713: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
714: if ($count) {
715: $r->print(&Apache::loncommon::start_data_table_row());
716: }
717: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
718: my $content = $todisplay{$scope}{$key};
719: if ($chg eq 'delete') {
720: $showstart = &mt('Deleted');
721: $showend = $showstart;
722: } else {
723: $showstart = localtime($start);
724: if ($end == 0) {
725: $showend = &mt('No end date');
726: } else {
727: $showend = localtime($end);
728: }
729: }
730: $r->print('<td>'.&mt($scope_desc{$scope}));
731: if (($scope eq 'course') || ($scope eq 'group')) {
732: if ($chg ne 'delete') {
733: my $cid = $content->{'domain'}.'_'.$content->{'number'};
734: my %course_description = &Apache::lonnet::coursedescription($cid);
735: $r->print('<br />('.$course_description{'description'}.')');
736: }
737: }
738: $r->print('</td><td>'.&mt('Start: ').$showstart.
739: '<br />'.&mt('End: ').$showend.'</td><td>');
740: if ($chg ne 'delete') {
741: if ($scope eq 'guest') {
742: $r->print(&mt('Passphrase').': '.$content->{'password'});
743: } elsif ($scope eq 'course' || $scope eq 'group') {
744: $r->print('<table><tr>');
745: $r->print('<th>'.&mt('Roles').'</th><th>'.
746: &mt('Access').'</th><th>'.
747: &mt('Sections').'</th>');
748: if ($scope eq 'course') {
749: $r->print('<th>'.&mt('Groups').'</th>');
750: } else {
751: $r->print('<th>'.&mt('Teams').'</th>');
752: }
753: $r->print('</tr>');
754: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
755: $r->print('<tr>');
756: foreach my $item ('role','access','section','group') {
757: $r->print('<td>');
758: if ($item eq 'role') {
759: my $ucscope = $scope;
760: $ucscope =~ s/^(\w)/uc($1)/e;
761: my $role_output;
762: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
763: if ($role eq 'all') {
764: $role_output .= $role.',';
765: } elsif ($role =~ /^cr/) {
766: $role_output .= (split('/',$role))[3].',';
767: } else {
768: $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
769: }
770: }
771: $role_output =~ s/,$//;
772: $r->print($role_output);
773: } else {
774: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
775: }
776: $r->print('</tr>');
777: }
778: $r->print("</table>");
779: }
780: $r->print("</tr></table>");
781: } elsif ($scope eq 'domains') {
782: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
783: } elsif ($scope eq 'users') {
784: my $curr_user_list = &sort_users($content->{'users'});
785: $r->print(&mt('Users: ').$curr_user_list);
786: } else {
787: $r->print(' ');
788: }
789: } else {
790: $r->print(' ');
791: }
792: $r->print('</td>');
793: $r->print(&Apache::loncommon::end_data_table_row());
794: $count ++;
795: }
796: }
797: }
798:
799:
800: sub update_access {
801: my ($r,$url,$group,$port_path) = @_;
802: my $totalprocessed = 0;
803: my %processing;
804: my %title = (
805: 'activate' => 'New control(s) added',
806: 'delete' => 'Existing control(s) deleted',
807: 'update' => 'Existing control(s) modified',
808: );
809: my $changes;
810: foreach my $chg (sort(keys(%title))) {
811: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
812: $totalprocessed += @{$processing{$chg}};
813: foreach my $num (@{$processing{$chg}}) {
814: my $scope = $env{'form.scope_'.$num};
815: my ($start,$end) = &get_dates_from_form($num);
816: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
817: if ($chg eq 'delete') {
818: $$changes{$chg}{$newkey} = 1;
819: } else {
820: $$changes{$chg}{$newkey} =
821: &build_access_record($num,$scope,$start,$end,$chg);
822: }
823: }
824: }
825: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
826: $r->print('<h3>'.&mt('Allowing others to retrieve file: [_1]',
827: $port_path.$file_name).'</h3>'."\n");
828: $file_name = &prepend_group($file_name);
829: my ($uname,$udom) = &get_name_dom();
830: my ($errors,$outcome,$deloutcome,$new_values,$translation);
831: if ($totalprocessed) {
832: ($outcome,$deloutcome,$new_values,$translation) =
833: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
834: $uname);
835: }
836: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
837: $uname);
838: my %access_controls =
839: &Apache::lonnet::get_access_controls($current_permissions,
840: $group,$file_name);
841: if ($totalprocessed) {
842: if ($outcome eq 'ok') {
843: my $updated_controls = $access_controls{$file_name};
844: my ($showstart,$showend);
845: $r->print(&Apache::loncommon::start_data_table());
846: $r->print(&Apache::loncommon::start_data_table_header_row());
847: $r->print('<th>'.&mt('Type of change').'</th><th>'.
848: &mt('Access control').'</th><th>'.&mt('Dates available').
849: '</th><th>'.&mt('Additional information').'</th>');
850: $r->print(&Apache::loncommon::end_data_table_header_row());
851: foreach my $chg (sort(keys(%processing))) {
852: if (@{$processing{$chg}} > 0) {
853: if ($chg eq 'delete') {
854: if (!($deloutcome eq 'ok')) {
855: $errors .='<span class="LC_error">'.
856: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
857: '</span>';
858: next;
859: }
860: }
861: my $numchgs = @{$processing{$chg}};
862: $r->print(&Apache::loncommon::start_data_table_row());
863: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
864: '.</td>');
865: my $count = 0;
866: my %todisplay;
867: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
868: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
869: my $newkey = $key;
870: if ($chg eq 'activate') {
871: $newkey =~ s/^(\d+)/$$translation{$1}/;
872: }
873: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
874: }
875: &build_access_summary($r,$count,$chg,%todisplay);
876: }
877: }
878: $r->print(&Apache::loncommon::end_data_table());
879: } else {
880: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
881: $errors .= '<span class="LC_error">'.
882: &mt('A problem occurred storing access control settings: [_1]',$outcome).
883: '</span>';
884: }
885: }
886: if ($errors) {
887: $r->print($errors);
888: }
889: }
890: my $allnew = 0;
891: my $totalnew = 0;
892: my $status = 'new';
893: my ($firstitem,$lastitem);
894: foreach my $newitem ('course','group','domains','users') {
895: $allnew += $env{'form.new'.$newitem};
896: }
897: if ($allnew > 0) {
898: my $now = time;
899: my $then = $now + (60*60*24*180); # six months approx.
900: &open_form($r,$url);
901: foreach my $newitem ('course','group','domains','users') {
902: if ($env{'form.new'.$newitem} > 0) {
903: $r->print('<br />'.&mt('Add new <b>[_1]-based</b> access control for portfolio file: <b>[_2]</b>',$newitem,$env{'form.currentpath'}.$env{'form.selectfile'}).'<br /><br />');
904: $firstitem = $totalnew;
905: $lastitem = $totalnew + $env{'form.new'.$newitem};
906: $totalnew = $lastitem;
907: my @numbers;
908: for (my $i=$firstitem; $i<$lastitem; $i++) {
909: push (@numbers,$i);
910: }
911: &display_access_row($r,$status,$newitem,\@numbers,
912: $access_controls{$file_name},$now,$then);
913: }
914: }
915: &close_form($r,$url);
916: } else {
917: my %anchor_fields = (
918: 'currentpath' => $env{'form.currentpath'},
919: 'access' => $env{'form.selectfile'}
920: );
921: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
922: delete $anchor_fields{'access'};
923: $r->print(' '.&make_anchor($url,\%anchor_fields,&mt('Return to directory listing')));
924: }
925: return;
926: }
927:
928: sub build_access_record {
929: my ($num,$scope,$start,$end,$chg) = @_;
930: my $record = {
931: type => $scope,
932: time => {
933: start => $start,
934: end => $end
935: },
936: };
937:
938: if ($scope eq 'guest') {
939: $record->{'password'} = $env{'form.password'};
940: } elsif (($scope eq 'course') || ($scope eq 'group')) {
941: $record->{'domain'} = $env{'form.crsdom_'.$num};
942: $record->{'number'} = $env{'form.crsnum_'.$num};
943: my @role_ids;
944: my @delete_role_ids =
945: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
946: my @preserves =
947: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
948: if (@delete_role_ids) {
949: foreach my $id (@preserves) {
950: if (grep {$_ = $id} (@delete_role_ids)) {
951: next;
952: }
953: push(@role_ids,$id);
954: }
955: } else {
956: push(@role_ids,@preserves);
957: }
958:
959: my $next_id = $env{'form.add_role_'.$num};
960: if ($next_id) {
961: push(@role_ids,$next_id);
962: }
963:
964: foreach my $id (@role_ids) {
965: my (@roles,@accesses,@sections,@groups);
966: if (($id == $next_id) && ($chg eq 'update')) {
967: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
968: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
969: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
970: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
971: } else {
972: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
973: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
974: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
975: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
976: }
977: $record->{'roles'}{$id}{'role'} = \@roles;
978: $record->{'roles'}{$id}{'access'} = \@accesses;
979: $record->{'roles'}{$id}{'section'} = \@sections;
980: $record->{'roles'}{$id}{'group'} = \@groups;
981: }
982: } elsif ($scope eq 'domains') {
983: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
984: $record->{'dom'} = \@doms;
985: } elsif ($scope eq 'users') {
986: my $userlist = $env{'form.users_'.$num};
987: $userlist =~ s/\s+//sg;
988: my %userhash = map { ($_,1) } (split(/,/,$userlist));
989: foreach my $user (keys(%userhash)) {
990: my ($uname,$udom) = split(/:/,$user);
991: push(@{$record->{'users'}}, {
992: 'uname' => $uname,
993: 'udom' => $udom
994: });
995: }
996: }
997: return $record;
998: }
999:
1000: sub get_dates_from_form {
1001: my ($id) = @_;
1002: my $startdate;
1003: my $enddate;
1004: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
1005: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
1006: if ( exists ($env{'form.noend_'.$id}) ) {
1007: $enddate = 0;
1008: }
1009: return ($startdate,$enddate);
1010: }
1011:
1012: sub sort_users {
1013: my ($users) = @_;
1014: my @curr_users = map {
1015: $_->{'uname'}.':'.$_->{'udom'}
1016: } (@{$users});
1017: my $curr_user_list = join(",\n",sort(@curr_users));
1018: return $curr_user_list;
1019: }
1020:
1021: sub access_setting_table {
1022: my ($r,$access_controls) = @_;
1023: my ($public,$publictext);
1024: $publictext = &mt('Off');
1025: my ($guest,$guesttext);
1026: $guesttext = &mt('Off');
1027: my @courses = ();
1028: my @groups = ();
1029: my @domains = ();
1030: my @users = ();
1031: my $now = time;
1032: my $then = $now + (60*60*24*180); # six months approx.
1033: my ($num,$scope,$publicnum,$guestnum);
1034: my (%acl_count,%end,%start);
1035: foreach my $key (sort(keys(%{$access_controls}))) {
1036: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1037: if ($scope eq 'public') {
1038: $public = $key;
1039: $publicnum = $num;
1040: $publictext = &acl_status($start{$key},$end{$key},$now);
1041: } elsif ($scope eq 'guest') {
1042: $guest=$key;
1043: $guestnum = $num;
1044: $guesttext = &acl_status($start{$key},$end{$key},$now);
1045: } elsif ($scope eq 'course') {
1046: push(@courses,$key);
1047: } elsif ($scope eq 'group') {
1048: push(@groups,$key);
1049: } elsif ($scope eq 'domains') {
1050: push(@domains,$key);
1051: } elsif ($scope eq 'users') {
1052: push(@users,$key);
1053: }
1054: $acl_count{$scope} ++;
1055: }
1056: $r->print('<table border="0"><tr><td valign="top">');
1057: $r->print('<h3>'.&mt('Public access:').' '.$publictext.'</h3>');
1058: $r->print(&Apache::loncommon::start_data_table());
1059: $r->print(&Apache::loncommon::start_data_table_header_row());
1060: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1061: $r->print(&Apache::loncommon::end_data_table_header_row());
1062: $r->print(&Apache::loncommon::start_data_table_row());
1063: if ($public) {
1064: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
1065: &dateboxes($publicnum,$start{$public},$end{$public}).'</td>');
1066: } else {
1067: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
1068: &dateboxes('0',$now,$then).'</td>');
1069: }
1070: $r->print(&Apache::loncommon::end_data_table_row());
1071: $r->print(&Apache::loncommon::end_data_table());
1072: $r->print('</td><td width="40"> </td><td valign="top">');
1073: $r->print('<h3>'.&mt('Passphrase-protected access:').' '.$guesttext.'</h3>');
1074: $r->print(&Apache::loncommon::start_data_table());
1075: $r->print(&Apache::loncommon::start_data_table_header_row());
1076: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1077: '</th><th>'. &mt('Passphrase').'</th>');
1078: $r->print(&Apache::loncommon::end_data_table_header_row());
1079: $r->print(&Apache::loncommon::start_data_table_row());
1080: my $passwd;
1081: if ($guest) {
1082: $passwd = $$access_controls{$guest}{'password'};
1083: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1084: &dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
1085: } else {
1086: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1087: &dateboxes('1',$now,$then).'</td>');
1088: }
1089: $r->print('<td><input type="text" size="15" name="password" value="'.
1090: $passwd.'" /></td>');
1091: $r->print(&Apache::loncommon::end_data_table_row());
1092: $r->print(&Apache::loncommon::end_data_table());
1093: # $r->print('</td></tr><tr><td colspan="3"> </td></tr><tr><td valign="top">');
1094: # &access_element($r,'domains',\%acl_count,\@domains,$access_controls,$now,$then);
1095: # $r->print('</td><td> </td><td valign="top">');
1096: # &access_element($r,'users',\%acl_count,\@users,$access_controls,$now,$then);
1097: # $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
1098: # if (@courses > 0 || @groups > 0) {
1099: # $r->print('<td colspan="3" valign="top">');
1100: # } else {
1101: # $r->print('<td valign="top">');
1102: # }
1103: # &access_element($r,'course',\%acl_count,\@courses,$access_controls,$now,$then);
1104: # $r->print('</td>');
1105: # if (@courses > 0 || @groups > 0) {
1106: # $r->print('</tr><tr><td colspan="3"> </td></tr><tr><td colspan="3" valign="top">');
1107: # } else {
1108: # $r->print('<td> </td><td valign="top">');
1109: # }
1110: # &access_element($r,'group',\%acl_count,\@groups,$access_controls,$now,$then);
1111: $r->print('</td></tr></table>');
1112: }
1113:
1114: sub acl_status {
1115: my ($start,$end,$now) = @_;
1116: if ($start > $now) {
1117: return &mt('Inactive');
1118: }
1119: if ($end && $end<$now) {
1120: return &mt('Inactive');
1121: }
1122: return &mt('Active');
1123: }
1124:
1125: sub access_element {
1126: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1127: my $title = $type;
1128: $title =~ s/s$//;
1129: $title =~ s/^(\w)/uc($1)/e;
1130: $r->print('<h3>'.&mt('[_1]-based conditional access: ',$title));
1131: if ($$acl_count{$type}) {
1132: $r->print($$acl_count{$type}.' ');
1133: if ($$acl_count{$type} > 1) {
1134: $r->print(&mt('conditions'));
1135: } else {
1136: $r->print(&mt('condition'));
1137: }
1138: } else {
1139: $r->print(&mt('Off'));
1140: }
1141: $r->print('</h3>');
1142: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1143: return;
1144: }
1145:
1146: sub display_access_row {
1147: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1148: if (@{$items} > 0) {
1149: my @all_doms;
1150: my $colspan = 3;
1151: my $uctype = $type;
1152: $uctype =~ s/^(\w)/uc($1)/e;
1153: $r->print(&Apache::loncommon::start_data_table());
1154: $r->print(&Apache::loncommon::start_data_table_header_row());
1155: $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
1156: &mt('Dates available').'</th>');
1157: if (($type eq 'course') || ($type eq 'group')) {
1158: $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
1159: '</th>');
1160: $colspan ++;
1161: } elsif ($type eq 'domains') {
1162: @all_doms = &Apache::loncommon::get_domains();
1163: }
1164: $r->print(&Apache::loncommon::end_data_table_header_row());
1165: foreach my $key (@{$items}) {
1166: $r->print(&Apache::loncommon::start_data_table_row());
1167: if (($type eq 'course') || ($type eq 'group')) {
1168: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1169: } elsif ($type eq 'domains') {
1170: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1171: $then);
1172: } elsif ($type eq 'users') {
1173: &users_row($r,$status,$key,$access_controls,$now,$then);
1174: }
1175: $r->print(&Apache::loncommon::end_data_table_row());
1176: }
1177: if ($status eq 'old') {
1178: $r->print(&Apache::loncommon::start_data_table_row());
1179: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1180: '</td>');
1181: $r->print(&Apache::loncommon::end_data_table_row());
1182: }
1183: $r->print(&Apache::loncommon::end_data_table());
1184: } else {
1185: $r->print(&mt('No [_1]-based conditions defined.<br />',$type).
1186: &additional_item($type));
1187: }
1188: return;
1189: }
1190:
1191: sub course_js {
1192: return qq|
1193: <script type="text/javascript">
1194: function setRoleOptions(caller,num,cdom,cnum,type) {
1195: addIndexnum = getCallerIndex(caller);
1196: updateIndexnum = getIndex('update',num);
1197: if (caller.checked) {
1198: document.portform.elements[updateIndexnum].checked = true;
1199: var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1200: var title = 'Roles_Chooser';
1201: var options = 'scrollbars=1,resizable=1,menubar=0';
1202: options += ',width=700,height=600';
1203: rolebrowser = open(url,title,options,'1');
1204: rolebrowser.focus();
1205: } else {
1206: for (var j=0;j<5;j++) {
1207: document.portform.elements[addIndexnum+j].value = '';
1208: }
1209: }
1210: }
1211:
1212: function getCallerIndex(caller) {
1213: for (var i=0;i<document.portform.elements.length;i++) {
1214: if (document.portform.elements[i] == caller) {
1215: return i;
1216: }
1217: }
1218: return -1;
1219: }
1220:
1221: function getIndex(name,value) {
1222: for (var i=0;i<document.portform.elements.length;i++) {
1223: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1224: return i;
1225: }
1226: }
1227: return -1;
1228: }
1229:
1230: </script>
1231: |;
1232: }
1233:
1234: sub course_row {
1235: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1236: my $content;
1237: my $defdom = $env{'user.domain'};
1238: if ($status eq 'old') {
1239: $content = $$access_controls{$item};
1240: $defdom = $content->{'domain'};
1241: }
1242: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1243: .&course_js();
1244: my $crsgrptext = 'Groups';
1245: if ($type eq 'group') {
1246: $crsgrptext = 'Teams';
1247: }
1248: my $uctype = $type;
1249: $uctype =~ s/^(\w)/uc($1)/e;
1250: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1251: $type);
1252: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1253: if ($status eq 'old') {
1254: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1255: my %course_description = &Apache::lonnet::coursedescription($cid);
1256: $r->print('<td><input type="hidden" name="crsdom_'.$num.'" value="'.$content->{'domain'}.'" /><input type="hidden" name="crsnum_'.$num.'" value="'.$content->{'number'}.'" />'.$course_description{'description'}.'</td>');
1257: } elsif ($status eq 'new') {
1258: $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,undef,undef,$uctype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
1259: }
1260: $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
1261: $r->print('<td><table><tr>');
1262: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
1263: &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
1264: &mt($crsgrptext).'</th></tr>');
1265: if ($status eq 'old') {
1266: my $max_id = 0;
1267: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1268: if ($role_id > $max_id) {
1269: $max_id = $role_id;
1270: }
1271: $max_id ++;
1272: my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display');
1273: $r->print('<tr><td><span style="white-space: nowrap"><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></span><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
1274: }
1275: $r->print('</table><br />'.&mt('Add a roles-based condition').' <input type="checkbox" name ="add_role_'.$num.'" onClick="javascript:setRoleOptions(this,'."'$num','$content->{'domain'}','$content->{'number'}','$uctype'".')" value="'.$max_id.'" /><input type="hidden" name="role_'.$num.'_'.$max_id.'" /><input type="hidden" name="access_'.$num.'_'.$max_id.'" /><input type="hidden" name="section_'.$num.'_'.$max_id.'" /><input type="hidden" name="group_'.$num.'_'.$max_id.'" /></td>');
1276: } elsif ($status eq 'new') {
1277: my $role_id = 1;
1278: my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
1279: $r->print('<tr><td><input type="checkbox" name="add_role_'.$num.'" value="'.$role_id.'" checked="checked" />'.&mt('Add').'<input type="hidden" name="grplist_'.$num.'_'.$role_id.'" /></td>'.$role_selects);
1280: $r->print('</tr></table></td>');
1281: }
1282: return;
1283: }
1284:
1285: sub domains_row {
1286: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1287: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1288: 'domains');
1289: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true">'.
1290: ' <option value="">'.&mt('Please select').'</option>';
1291: if ($status eq 'old') {
1292: my $content = $$access_controls{$item};
1293: foreach my $dom (@{$all_doms}) {
1294: if ((@{$content->{'dom'}} > 0)
1295: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1296: $dom_select .= '<option value="'.$dom.'" selected>'.
1297: $dom.'</option>';
1298: } else {
1299: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1300: }
1301: }
1302: } else {
1303: foreach my $dom (@{$all_doms}) {
1304: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1305: }
1306: }
1307: $dom_select .= '</select>';
1308: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1309: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1310: }
1311:
1312: sub users_row {
1313: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1314: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1315: 'users');
1316: my $curr_user_list;
1317: if ($status eq 'old') {
1318: my $content = $$access_controls{$item};
1319: $curr_user_list = &sort_users($content->{'users'});
1320: }
1321: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt("Format for users' username:domain information:").'<br /><tt>sparty:msu,illini:uiuc ... etc.</tt><br /><textarea name="users_'.$num.'" cols="30" rows="5">'.$curr_user_list.'</textarea></td><td>'.&dateboxes($num,$start,$end).'</td>');
1322: }
1323:
1324: sub additional_item {
1325: my ($type) = @_;
1326: my $output = &mt('Add new [_1] condition(s)?',$type).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1327: return $output;
1328: }
1329:
1330: sub actionbox {
1331: my ($status,$num,$scope) = @_;
1332: my $output = '<span style="white-space: nowrap"><label>';
1333: if ($status eq 'new') {
1334: $output .= '<input type="checkbox" name="activate" value="'.$num.'" />'.
1335: &mt('Activate');
1336: } else {
1337: $output .= '<input type="checkbox" name="delete" value="'.$num.
1338: '" />'.&mt('Delete').'</label></span><br /><span style="white-space: nowrap">'.
1339: '<label><input type="checkbox" name="update" value="'.
1340: $num.'" />'.&mt('Update');
1341: }
1342: $output .= '</label></span><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1343: return $output;
1344: }
1345:
1346: sub dateboxes {
1347: my ($num,$start,$end) = @_;
1348: my $noend;
1349: if ($end == 0) {
1350: $noend = 'checked="checked"';
1351: }
1352: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1353: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1354: undef,undef,1);
1355: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1356: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1357: undef,undef,1). ' <span style="white-space: nowrap"><label>'.
1358: '<input type="checkbox" name="noend_'.
1359: $num.'" '.$noend.' />'.&mt('No end date').
1360: '</label></span>';
1361:
1362: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1363: return $output;
1364: }
1365:
1366: sub unpack_acc_key {
1367: my ($acc_key) = @_;
1368: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1369: return ($num,$scope,$end,$start);
1370: }
1371:
1372: sub set_identifiers {
1373: my ($status,$item,$now,$then,$scope) = @_;
1374: if ($status eq 'old') {
1375: return(&unpack_acc_key($item));
1376: } else {
1377: return($item,$scope,$then,$now);
1378: }
1379: }
1380:
1381: sub role_selectors {
1382: my ($num,$role_id,$status,$type,$content,$caller) = @_;
1383: my ($output,$cdom,$cnum,$longid);
1384: if ($caller eq 'display') {
1385: $longid = '_'.$num.'_'.$role_id;
1386: if ($status eq 'new') {
1387: foreach my $item ('role','access','section','group') {
1388: $output .= '<td><select name="'.$item.$longid.'">'.
1389: '<option value="">'.&mt('Pick [_1] first',$type).
1390: '</option></select></td>';
1391: }
1392: return $output;
1393: } else {
1394: $cdom = $$content{'domain'};
1395: $cnum = $$content{'number'};
1396: }
1397: } elsif ($caller eq 'rolepicker') {
1398: $cdom = $env{'form.cdom'};
1399: $cnum = $env{'form.cnum'};
1400: }
1401: my $uctype = $type;
1402: $uctype =~ s/^(\w)/uc($1)/e;
1403: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1404: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$uctype);
1405: if (!@{$sections}) {
1406: @{$sections} = ('none');
1407: } else {
1408: unshift(@{$sections},('all','none'));
1409: }
1410: if (!@{$groups}) {
1411: @{$groups} = ('none');
1412: } else {
1413: unshift(@{$groups},('all','none'));
1414: }
1415: my @allacesses = sort(keys(%{$accesshash}));
1416: my (%sectionhash,%grouphash);
1417: foreach my $sec (@{$sections}) {
1418: $sectionhash{$sec} = $sec;
1419: }
1420: foreach my $grp (@{$groups}) {
1421: $grouphash{$grp} = $grp;
1422: }
1423: my %lookup = (
1424: 'role' => $rolehash,
1425: 'access' => $accesshash,
1426: 'section' => \%sectionhash,
1427: 'group' => \%grouphash,
1428: );
1429: my @allaccesses = sort(keys(%{$accesshash}));
1430: my %allitems = (
1431: 'role' => $allroles,
1432: 'access' => \@allaccesses,
1433: 'section' => $sections,
1434: 'group' => $groups,
1435: );
1436: foreach my $item ('role','access','section','group') {
1437: $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
1438: foreach my $entry (@{$allitems{$item}}) {
1439: if ($caller eq 'display') {
1440: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1441: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1442: $output .= ' <option value="'.$entry.'" selected>'.
1443: $lookup{$item}{$entry}.'</option>';
1444: next;
1445: }
1446: }
1447: $output .= ' <option value="'.$entry.'">'.
1448: $lookup{$item}{$entry}.'</option>';
1449: }
1450: $output .= '</select>';
1451: }
1452: $output .= '</td>';
1453: return $output;
1454: }
1455:
1456: sub role_options_window {
1457: my ($r) = @_;
1458: my $cdom = $env{'form.cdom'};
1459: my $cnum = $env{'form.cnum'};
1460: my $type = $env{'form.type'};
1461: my $addindex = $env{'form.setroles'};
1462: my $grouptitle = 'Groups';
1463: if ($type eq 'Group') {
1464: $grouptitle = 'Teams';
1465: }
1466: my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker');
1467: $r->print(<<"END_SCRIPT");
1468: <script type="text/javascript">
1469: function setRoles() {
1470: var addidx = $addindex+1;
1471: for (var i=0; i<4; i++) {
1472: var copylist = '';
1473: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1474: if (document.rolepicker.elements[i].options[j].selected) {
1475: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1476: }
1477: }
1478: copylist = copylist.substr(0,copylist.length-1);
1479: opener.document.portform.elements[addidx+i].value = copylist;
1480: }
1481: self.close();
1482: }
1483: </script>
1484: END_SCRIPT
1485: $r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
1486: $r->print('<form name="rolepicker" action="/adm/portfolio" method="post"><table><tr><th>'.&mt('Roles').'</th><th>'.&mt('[_1] status',$type).'</th><th>'.&mt('Sections').'</th><th>'.&mt($grouptitle).'</th></tr><tr>'.$role_selects.'</tr></table><br /><input type="button" name="rolepickbutton" value="Save selections" onclick="setRoles()" />');
1487: return;
1488: }
1489:
1490: sub select_files {
1491: my ($r) = @_;
1492: if ($env{'form.continue'} eq 'true') {
1493: # here we update the selections for the currentpath
1494: # eventually, have to handle removing those not checked, but . . .
1495: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1496: if (scalar(@items)){
1497: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1498: }
1499: } else {
1500: #empty the file for a fresh start
1501: &Apache::lonnet::clear_selected_files($env{'user.name'});
1502: }
1503: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1504: my $java_files = join ",", @files;
1505: if ($java_files) {
1506: $java_files.=',';
1507: }
1508: my $javascript =(<<ENDSMP);
1509: <script type="text/javascript">
1510: function finishSelect() {
1511: ENDSMP
1512: $javascript .= 'fileList = "'.$java_files.'";';
1513: $javascript .= (<<ENDSMP);
1514: for (i=0;i<document.forms.checkselect.length;i++) {
1515: if (document.forms.checkselect[i].checked){
1516: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1517: }
1518: }
1519: opener.document.forms.lonhomework.$env{'form.fieldname'}.value=fileList;
1520: self.close();
1521: }
1522: </script>
1523: ENDSMP
1524: $r->print($javascript);
1525: $r->print("<h1>Select portfolio files</h1>
1526: Check as many as you wish in response to the problem.<br />");
1527: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1528: if (@otherfiles) {
1529: $r->print("<strong>Files selected from other directories:</strong><br />");
1530: foreach my $file (@otherfiles) {
1531: $r->print($file."<br />");
1532: }
1533: }
1534: }
1535:
1536: sub upload {
1537: my ($r,$url,$group)=@_;
1538: my $fname=$env{'form.uploaddoc.filename'};
1539: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1540: my $disk_quota = 20000; # expressed in k
1541: if (defined($group)) {
1542: my $grp_quota = &get_group_quota($group); # quota expressed in k
1543: if ($grp_quota ne '') {
1544: $disk_quota = $grp_quota;
1545: } else {
1546: $disk_quota = 0;
1547: }
1548: }
1549: $fname=&Apache::lonnet::clean_filename($fname);
1550:
1551: my $portfolio_root=&get_portfolio_root();
1552: my ($uname,$udom) = &get_name_dom();
1553: my $port_path = &get_port_path();
1554: # Fixme --- Move the checking for existing file to LOND error return
1555: my @dir_list=&get_dir_list($portfolio_root);
1556: my $found_file = 0;
1557: my $locked_file = 0;
1558: foreach my $line (@dir_list) {
1559: my ($file_name)=split(/\&/,$line,2);
1560: if ($file_name eq $fname){
1561: $file_name = $env{'form.currentpath'}.$file_name;
1562: $file_name = &prepend_group($file_name);
1563: $found_file = 1;
1564: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1565: $locked_file = 1;
1566: }
1567: }
1568: }
1569: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
1570: if (($current_disk_usage + $filesize) > $disk_quota){
1571: $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
1572: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1573: $r->print(&done('Back',$url));
1574: }
1575: elsif ($found_file){
1576: if ($locked_file){
1577: $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
1578: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
1579: $r->print(&done('Back',$url));
1580: } else {
1581: $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
1582: '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
1583: $r->print(&done('Back',$url));
1584: }
1585: } else {
1586: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1587: $port_path.$env{'form.currentpath'});
1588: if ($result !~ m|^/uploaded/|) {
1589: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1590: ') while trying to upload '.&display_file().'</span><br />');
1591: $r->print(&done('Back',$url));
1592: } else {
1593: $r->print(&done(undef,$url));
1594: }
1595: }
1596: }
1597:
1598: sub lock_info {
1599: my ($r,$url,$group) = @_;
1600: my ($uname,$udom) = &get_name_dom();
1601: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1602: $uname);
1603: my $file_name = $env{'form.lockinfo'};
1604: $file_name = &prepend_group($file_name);
1605: if (defined($file_name) && defined($$current_permissions{$file_name})) {
1606: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1607: next if (ref($array_item) ne 'ARRAY');
1608:
1609: my $filetext;
1610: if (defined($group)) {
1611: $filetext = '<strong>'.$env{'form.lockinfo'}.
1612: '</strong> (group: '.$group.')';
1613: } else {
1614: $filetext = '<strong>'.$file_name.'</strong>';
1615: }
1616:
1617: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
1618: '</strong><br />';
1619: if ($$array_item[-1] eq 'graded') {
1620: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1621: $filetext,$title));
1622: } elsif ($$array_item[-1] eq 'handback') {
1623: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
1624: $filetext,$title));
1625: } else {
1626: # submission style lock
1627: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1628: $filetext,$title));
1629: }
1630: my %course_description =
1631: &Apache::lonnet::coursedescription($$array_item[1]);
1632: if ( $course_description{'description'} ne '') {
1633: $r->print(&mt('In the course: <strong>[_1]</strong><br />',
1634: $course_description{'description'}));
1635: }
1636: }
1637: }
1638: $r->print(&done('Back',$url));
1639: return 'ok';
1640: }
1641:
1642: sub createdir {
1643: my ($r,$url)=@_;
1644: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1645: if ($newdir eq '') {
1646: $r->print('<span class="LC_error">'.
1647: &mt("Error: no directory name was provided.").
1648: '</span><br />');
1649: $r->print(&done(undef,$url));
1650: return;
1651: }
1652: my $portfolio_root = &get_portfolio_root();
1653: my @dir_list=&get_dir_list($portfolio_root);
1654: my $found_file = 0;
1655: foreach my $line (@dir_list) {
1656: my ($filename)=split(/\&/,$line,2);
1657: if ($filename eq $newdir){
1658: $found_file = 1;
1659: }
1660: }
1661: if ($found_file){
1662: $r->print('<span class="LC_error">'.'Unable to create a directory named <strong>'.$newdir.
1663: ' </strong>a file or directory by that name already exists.</span><br />');
1664: } else {
1665: my ($uname,$udom) = &get_name_dom();
1666: my $port_path = &get_port_path();
1667: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
1668: $port_path.$env{'form.currentpath'}.$newdir);
1669: if ($result ne 'ok') {
1670: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1671: ') while trying to create a new directory '.&display_file().'</span><br />');
1672: }
1673: }
1674: if ($newdir ne $env{'form.newdir'}) {
1675: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1676: }
1677: $r->print(&done(undef,$url));
1678: }
1679:
1680: sub get_portfolio_root {
1681: my ($uname,$udom) = &get_name_dom();
1682: my $path;
1683: if (defined($env{'form.group'})) {
1684: $path = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
1685: } else {
1686: $path = '/userfiles/portfolio';
1687: }
1688: return (&Apache::loncommon::propath($udom,$uname).$path);
1689: }
1690:
1691: sub get_group_quota {
1692: my ($group) = @_;
1693: my $group_quota;
1694: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1695: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1696: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
1697: if (%curr_groups) {
1698: my %group_info = &Apache::longroup::get_group_settings(
1699: $curr_groups{$group});
1700: $group_quota = $group_info{'quota'}; #expressed in Mb
1701: if ($group_quota) {
1702: $group_quota = 1000 * $group_quota; #expressed in k
1703: }
1704: }
1705: return $group_quota;
1706: }
1707:
1708: sub get_dir_list {
1709: my ($portfolio_root) = @_;
1710: my ($uname,$udom) = &get_name_dom();
1711: return &Apache::lonnet::dirlist($env{'form.currentpath'},
1712: $udom,$uname,$portfolio_root);
1713: }
1714:
1715: sub get_name_dom {
1716: my ($uname,$udom);
1717: if (defined($env{'form.group'})) {
1718: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1719: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
1720: } else {
1721: $udom = $env{'user.domain'};
1722: $uname = $env{'user.name'};
1723: }
1724: return ($uname,$udom);
1725: }
1726:
1727: sub prepend_group {
1728: my ($filename) = @_;
1729: if (defined($env{'form.group'})) {
1730: $filename = $env{'form.group'}.$filename;
1731: }
1732: return $filename;
1733: }
1734:
1735: sub get_namespace {
1736: my $namespace = 'portfolio';
1737: if (defined($env{'form.group'})) {
1738: my ($uname,$udom) = &get_name_dom();
1739: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
1740: }
1741: return $namespace;
1742: }
1743:
1744: sub get_port_path {
1745: my $port_path;
1746: if (defined($env{'form.group'})) {
1747: $port_path = "groups/$env{'form.group'}/portfolio";
1748: } else {
1749: $port_path = 'portfolio';
1750: }
1751: return $port_path;
1752: }
1753:
1754: sub missing_priv {
1755: my ($r,$url,$priv) = @_;
1756: my $longtext = {
1757: upload => 'upload files',
1758: delete => 'delete files',
1759: rename => 'rename files',
1760: setacl => 'set access controls for files',
1761: };
1762: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
1763: my $rtnlink = '<a href="'.$url;
1764: if ($url =~ /\?/) {
1765: $rtnlink .= '&';
1766: } else {
1767: $rtnlink .= '?';
1768: }
1769: $rtnlink .= 'currentpath='.$escpath;
1770: $r->print(&mt('<h3>Action disallowed</h3>'));
1771: $r->print(&mt('You do not have sufficient privileges to [_1] ',
1772: $longtext->{$priv}));
1773: if (defined($env{'form.group'})) {
1774: $r->print(&mt("in the group's file repository."));
1775: $rtnlink .= &group_args()
1776: } else {
1777: $r->print(&mt('in this portfolio.'));
1778: }
1779: $rtnlink .= '">'.&mt('Return to directory listing page').'</a>';
1780: $r->print('<br />'.$rtnlink);
1781: $r->print(&Apache::loncommon::end_page());
1782: return;
1783: }
1784:
1785: sub coursegrp_portfolio_header {
1786: my ($cdom,$cnum,$grp_desc)=@_;
1787: my $gpterm = &Apache::loncommon::group_term();
1788: my $ucgpterm = $gpterm;
1789: $ucgpterm =~ s/^(\w)/uc($1)/e;
1790: if ($env{'form.ref'}) {
1791: &Apache::lonhtmlcommon::add_breadcrumb
1792: ({href=>"/adm/coursegroups",
1793: text=>"Groups",
1794: title=>"Course Groups"});
1795: }
1796: &Apache::lonhtmlcommon::add_breadcrumb
1797: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
1798: text=>"$ucgpterm: $grp_desc",
1799: title=>"Go to group's home page"},
1800: {href=>"/adm/coursegrp_portfolio?".&group_args(),
1801: text=>"Group Portfolio",
1802: title=>"Display group portfolio"});
1803: my $output = &Apache::lonhtmlcommon::breadcrumbs(
1804: &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
1805: return $output;
1806: }
1807:
1808:
1809: sub handler {
1810: # this handles file management
1811: my $r = shift;
1812: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1813: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
1814: 'fieldname','mode','rename','continue','group','access','setnum',
1815: 'cnum','cdom','type','setroles','showversions','ref']);
1816: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
1817: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
1818: $url = $1.$2;
1819: $caller = $2;
1820: }
1821: my ($can_modify,$can_delete,$can_upload,$can_setacl);
1822: if ($caller eq 'coursegrp_portfolio') {
1823: # Needs to be in a course
1824: if (! ($env{'request.course.fn'})) {
1825: # Not in a course
1826: $env{'user.error.msg'}=
1827: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
1828: return HTTP_NOT_ACCEPTABLE;
1829: }
1830: my $earlyout = 0;
1831: my $view_permission =
1832: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1833: $env{'form.group'} =~ s/\W//g;
1834: $group = $env{'form.group'};
1835: if ($group) {
1836: ($uname,$udom) = &get_name_dom();
1837: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1838: $group);
1839: if (%curr_groups) {
1840: my %grp_content = &Apache::longroup::get_group_settings(
1841: $curr_groups{$group});
1842: $grp_desc = &unescape($grp_content{'description'});
1843: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
1844: $env{'request.course.id'}.'/'.$group))) {
1845: $portfolio_root = &get_portfolio_root();
1846: } else {
1847: $r->print('You do not have the privileges required to access the shared files space for this group.');
1848: $earlyout = 1;
1849: }
1850: } else {
1851: $r->print('Not a valid group for this course');
1852: $earlyout = 1;
1853: }
1854: $title = &mt('Group files').' for '.$group;
1855: } else {
1856: $r->print('Invalid group');
1857: $earlyout = 1;
1858: }
1859: if ($earlyout) { return OK; }
1860: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
1861: $can_modify = 1;
1862: $can_delete = 1;
1863: $can_upload = 1;
1864: $can_setacl = 1;
1865: } else {
1866: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
1867: $can_setacl = 1;
1868: }
1869: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
1870: $can_upload = 1;
1871: }
1872: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
1873: $can_modify = 1;
1874: }
1875: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
1876: $can_delete = 1;
1877: }
1878: }
1879: } else {
1880: ($uname,$udom) = &get_name_dom();
1881: $portfolio_root = &get_portfolio_root();
1882: $title = &mt('Portfolio Manager');
1883: $can_modify = 1;
1884: $can_delete = 1;
1885: $can_upload = 1;
1886: $can_setacl = 1;
1887: }
1888:
1889: my $port_path = &get_port_path();
1890: &Apache::loncommon::no_cache($r);
1891: &Apache::loncommon::content_type($r,'text/html');
1892: $r->send_http_header;
1893: # Give the LON-CAPA page header
1894: if ($env{"form.mode"} eq 'selectfile'){
1895: $r->print(&Apache::loncommon::start_page($title,undef,
1896: {'only_body' => 1}));
1897: } elsif ($env{'form.action'} eq 'rolepicker') {
1898: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
1899: {'no_nav_bar' => 1, }));
1900: } else {
1901: $r->print(&Apache::loncommon::start_page($title));
1902: }
1903: $r->rflush();
1904: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1905: $r->print('<span class="LC_error">'.
1906: 'No file was selected to upload.'.
1907: 'To upload a file, click <strong>Browse...</strong>'.
1908: ', select a file, then click <strong>Upload</strong>.'.
1909: '</span>');
1910: }
1911: if ($env{'form.meta'}) {
1912: &open_form($r,$url);
1913: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1914: $r->print('Edit the meta data<br />');
1915: &close_form($r,$url);
1916: }
1917: if ($env{'form.store'}) {
1918: }
1919:
1920: if ($env{'form.uploaddoc.filename'}) {
1921: if ($can_upload) {
1922: &upload($r,$url,$group);
1923: } else {
1924: &missing_priv($r,$url,'upload');
1925: }
1926: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1927: if ($can_delete) {
1928: &delete_confirmed($r,$url);
1929: } else {
1930: &missing_priv($r,$url,'delete');
1931: }
1932: } elsif ($env{'form.action'} eq 'delete') {
1933: if ($can_delete) {
1934: &delete($r,$url);
1935: } else {
1936: &missing_priv($r,$url,'delete');
1937: }
1938: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1939: if ($can_delete) {
1940: &delete_dir_confirmed($r,$url);
1941: } else {
1942: &missing_priv($r,$url,'delete');
1943: }
1944: } elsif ($env{'form.action'} eq 'deletedir') {
1945: if ($can_delete) {
1946: &delete_dir($r,$url);
1947: } else {
1948: &missing_priv($r,$url,'delete');
1949: }
1950: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1951: if ($can_modify) {
1952: &rename_confirmed($r,$url);
1953: } else {
1954: &missing_priv($r,$url,'rename');
1955: }
1956: } elsif ($env{'form.rename'}) {
1957: $env{'form.selectfile'} = $env{'form.rename'};
1958: $env{'form.action'} = 'rename';
1959: if ($can_modify) {
1960: &rename($r,$url);
1961: } else {
1962: &missing_priv($r,$url,'rename');
1963: }
1964: } elsif ($env{'form.access'}) {
1965: $env{'form.selectfile'} = $env{'form.access'};
1966: $env{'form.action'} = 'chgaccess';
1967: &display_access($r,$url,$group,$can_setacl,$port_path);
1968: } elsif ($env{'form.action'} eq 'chgaccess') {
1969: if ($can_setacl) {
1970: &update_access($r,$url,$group,$port_path);
1971: } else {
1972: &missing_priv($r,$url,'setacl');
1973: }
1974: } elsif ($env{'form.action'} eq 'rolepicker') {
1975: if ($can_setacl) {
1976: &role_options_window($r);
1977: } else {
1978: &missing_priv($r,$url,'setacl');
1979: }
1980: } elsif ($env{'form.createdir'}) {
1981: if ($can_upload) {
1982: &createdir($r,$url);
1983: } else {
1984: &missing_priv($r,$url,'upload');
1985: }
1986: } elsif ($env{'form.lockinfo'}) {
1987: &lock_info($r,$url,$group);
1988: } else {
1989: my $current_path='/';
1990: if ($env{'form.currentpath'}) {
1991: $current_path = $env{'form.currentpath'};
1992: }
1993: if ($caller eq 'coursegrp_portfolio') {
1994: &Apache::lonhtmlcommon::clear_breadcrumbs();
1995: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
1996: }
1997: my @dir_list=&get_dir_list($portfolio_root);
1998: if ($dir_list[0] eq 'no_such_dir'){
1999: # two main reasons for this:
2000: # 1) never been here, so directory structure not created
2001: # 2) back-button navigation after deleting a directory
2002: if ($current_path eq '/'){
2003: &Apache::lonnet::mkdiruserfile($uname,$udom,
2004: &get_port_path());
2005: } else {
2006: # some directory that snuck in get rid of the directory
2007: # from the recent pulldown, just in case
2008: &Apache::lonhtmlcommon::remove_recent('portfolio',
2009: [$current_path]);
2010: $current_path = '/'; # force it back to the root
2011: }
2012: # now grab the directory list again, for the first time
2013: @dir_list=&Apache::lonnet::dirlist($current_path,
2014: $udom,$uname,$portfolio_root);
2015: }
2016: # need to know if directory is empty so it can be removed if desired
2017: my $is_empty=(@dir_list == 2);
2018: &display_common($r,$url,$current_path,$is_empty,\@dir_list,
2019: $can_upload);
2020: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
2021: $can_upload,$can_modify,$can_delete,$can_setacl);
2022: $r->print(&Apache::loncommon::end_page());
2023: }
2024: return OK;
2025: }
2026:
2027: 1;
2028: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>