| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.54 2005/08/28 20:54:51 jj Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.55 2005/08/28 23:09:27 jj Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 39 | use constant MAX_SHOW_DEFAULT => 20; |
39 | use constant MAX_SHOW_DEFAULT => 20; |
| 40 | use constant NO_LOCAL_SET_STRING => 'No sets in this course yet'; |
40 | use constant NO_LOCAL_SET_STRING => 'No sets in this course yet'; |
| 41 | use constant SELECT_SET_STRING => 'Select a Set from this Course'; |
41 | use constant SELECT_SET_STRING => 'Select a Set from this Course'; |
| 42 | use constant SELECT_LOCAL_STRING => 'Select a Problem Collection'; |
42 | use constant SELECT_LOCAL_STRING => 'Select a Problem Collection'; |
| 43 | use constant MY_PROBLEMS => ' My Problems '; |
43 | use constant MY_PROBLEMS => ' My Problems '; |
| 44 | use constant MAIN_PROBLEMS => ' Main Problems '; |
44 | use constant MAIN_PROBLEMS => ' Unclassified Problems '; |
| 45 | use constant CREATE_SET_BUTTON => 'Create New Set'; |
45 | use constant CREATE_SET_BUTTON => 'Create New Set'; |
| 46 | use constant ALL_CHAPTERS => 'All Chapters'; |
46 | use constant ALL_CHAPTERS => 'All Chapters'; |
| 47 | use constant ALL_SUBJECTS => 'All Subjects'; |
47 | use constant ALL_SUBJECTS => 'All Subjects'; |
| 48 | use constant ALL_SECTIONS => 'All Sections'; |
48 | use constant ALL_SECTIONS => 'All Sections'; |
| 49 | use constant ALL_TEXTBOOKS => 'All Textbooks'; |
49 | use constant ALL_TEXTBOOKS => 'All Textbooks'; |
| … | |
… | |
| 65 | use constant SUCCESS => (1 << 2); |
65 | use constant SUCCESS => (1 << 2); |
| 66 | |
66 | |
| 67 | ## for additional problib buttons |
67 | ## for additional problib buttons |
| 68 | my %problib; ## filled in in global.conf |
68 | my %problib; ## filled in in global.conf |
| 69 | my %ignoredir = ( |
69 | my %ignoredir = ( |
| 70 | '.' => 1, '..' => 1, 'Library' => 1, |
70 | '.' => 1, '..' => 1, 'Library' => 1, 'CVS' => 1, |
| 71 | 'headers' => 1, 'macros' => 1, 'email' => 1, |
71 | 'headers' => 1, 'macros' => 1, 'email' => 1, |
| 72 | ); |
72 | ); |
| 73 | |
73 | |
| 74 | sub prepare_activity_entry { |
74 | sub prepare_activity_entry { |
| 75 | my $self=shift; |
75 | my $self=shift; |
| … | |
… | |
| 78 | return("In SetMaker as user $user"); |
78 | return("In SetMaker as user $user"); |
| 79 | } |
79 | } |
| 80 | |
80 | |
| 81 | ## This is for searching the disk for directories containing pg files. |
81 | ## This is for searching the disk for directories containing pg files. |
| 82 | ## to make the recursion work, this returns an array where the first |
82 | ## to make the recursion work, this returns an array where the first |
| 83 | ## item is the number of pg files in the directory. The second is a |
83 | ## item is the number of pg files in the directory. The second is a |
| 84 | ## list of directories which contain pg files. |
84 | ## list of directories which contain pg files. |
| 85 | ## |
85 | ## |
| 86 | ## If a directory contains only one pg file and at least one other |
86 | ## If a directory contains only one pg file and the directory name |
| 87 | ## file, the directory is considered to be part of the parent |
87 | ## is the same as the file name, then the directory is considered |
| 88 | ## directory (it is probably in a separate directory only because |
88 | ## to be part of the parent directory (it is probably in a separate |
| 89 | ## it has auxiliarly files that want to be kept together with the |
89 | ## directory only because it has auxiliary files that want to be |
| 90 | ## pg file). |
90 | ## kept together with the pg file). |
| 91 | ## |
91 | ## |
| 92 | ## If a directory has a file named "=library-ignore", it is never |
92 | ## If a directory has a file named "=library-ignore", it is never |
| 93 | ## included in the directory menu. If a directory contains a file |
93 | ## included in the directory menu. If a directory contains a file |
| 94 | ## called "=library-combine-up", then its pg are included with those |
94 | ## called "=library-combine-up", then its pg are included with those |
| 95 | ## in the parent directory (and the directory does not appear in the |
95 | ## in the parent directory (and the directory does not appear in the |
| 96 | ## menu). If it has a file called "=library-no-combine" then it is |
96 | ## menu). If it has a file called "=library-no-combine" then it is |
| 97 | ## always listed as a separate directory even if it contains only one |
97 | ## always listed as a separate directory even if it contains only one |
| 98 | ## pg file. |
98 | ## pg file. |
| 99 | |
99 | |
| 100 | sub get_library_sets { |
100 | sub get_library_sets { |
| 101 | my $top = shift; my $dir = shift; |
101 | my $top = shift; my $dir = shift; |
| 102 | # ignore directories that give us an error |
102 | # ignore directories that give us an error |
| 103 | my @lis = eval { readDirectory($dir) }; |
103 | my @lis = eval { readDirectory($dir) }; |
| 104 | if ($@) { |
104 | if ($@) { |
| 105 | warn $@; |
105 | warn $@; |
| 106 | return (0); |
106 | return (0); |
| 107 | } |
107 | } |
| 108 | return (0) if grep /^=library-ignore$/, @lis; |
108 | return (0) if grep /^=library-ignore$/, @lis; |
| 109 | |
109 | |
|
|
110 | my @pgfiles = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$dir/$_"} @lis; |
|
|
111 | my $pgcount = scalar(@pgfiles); |
|
|
112 | my $pgname = $dir; $pgname =~ s!.*/!!; $pgname .= '.pg'; |
|
|
113 | my $combineUp = ($pgcount == 1 && $pgname eq $pgfiles[0] && !(grep /^=library-no-combine$/, @lis)); |
|
|
114 | |
| 110 | my @pgdirs; |
115 | my @pgdirs; |
| 111 | |
|
|
| 112 | my $pgcount = scalar(grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$dir/$_"} @lis); |
|
|
| 113 | my $others = scalar(grep { (!m/\.pg$/ || m/(Header|-text)\.pg$/) && |
|
|
| 114 | !m/(\.(tmp|bak)|~)$/ && -f "$dir/$_" } @lis); |
|
|
| 115 | |
|
|
| 116 | my @dirs = grep {!$ignoredir{$_} and -d "$dir/$_"} @lis; |
116 | my @dirs = grep {!$ignoredir{$_} and -d "$dir/$_"} @lis; |
| 117 | if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs} |
117 | if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs} |
| 118 | foreach my $subdir (@dirs) { |
118 | foreach my $subdir (@dirs) { |
| 119 | my @results = get_library_sets(0, "$dir/$subdir"); |
119 | my @results = get_library_sets(0, "$dir/$subdir"); |
| 120 | $pgcount += shift @results; push(@pgdirs,@results); |
120 | $pgcount += shift @results; push(@pgdirs,@results); |
| 121 | } |
121 | } |
| 122 | |
122 | |
| 123 | return ($pgcount, @pgdirs) if $top || $pgcount == 0 || grep /^=library-combine-up$/, @lis; |
123 | return ($pgcount, @pgdirs) if $top || $combineUp || grep /^=library-combine-up$/, @lis; |
| 124 | return (0,@pgdirs,$dir) if $pgcount > 1 || $others == 0 || grep /^=library-no-combine$/, @lis; |
124 | return (0,@pgdirs,$dir); |
| 125 | return ($pgcount, @pgdirs); |
|
|
| 126 | } |
125 | } |
| 127 | |
126 | |
| 128 | sub get_library_pgs { |
127 | sub get_library_pgs { |
| 129 | my $top = shift; my $base = shift; my $dir = shift; |
128 | my $top = shift; my $base = shift; my $dir = shift; |
| 130 | my @lis = readDirectory("$base/$dir"); |
129 | my @lis = readDirectory("$base/$dir"); |
| 131 | return () if grep /^=library-ignore$/, @lis; |
130 | return () if grep /^=library-ignore$/, @lis; |
| 132 | return () if !$top && grep /^=library-no-combine$/, @lis; |
131 | return () if !$top && grep /^=library-no-combine$/, @lis; |
| 133 | |
132 | |
| 134 | my @pgs = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$base/$dir/$_"} @lis; |
133 | my @pgs = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$base/$dir/$_"} @lis; |