Annotation of loncom/Lond.pm, revision 1.4
1.1 droeschl 1: # The LearningOnline Network
2: #
1.4 ! droeschl 3: # $Id: Lond.pm,v 1.3 2012/04/26 20:00:57 droeschl Exp $
1.1 droeschl 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: ###
28:
29: #NOTE perldoc at the end of file
1.4 ! droeschl 30: #TODO move remaining lond functions into this
1.1 droeschl 31:
32: package LONCAPA::Lond;
33:
34: use strict;
35: use lib '/home/httpd/lib/perl/';
36:
37: use LONCAPA;
38: use Apache::lonnet;
39: use GDBM_File;
40:
41:
42: sub dump_with_regexp {
1.4 ! droeschl 43: my ( $tail, $clientversion ) = @_;
1.2 droeschl 44: my ( $udom, $uname, $namespace, $regexp, $range ) =
45: split /:/, $tail;
1.1 droeschl 46:
1.4 ! droeschl 47: $regexp = $regexp ? unescape($regexp) : '.';
1.1 droeschl 48:
49: my ($start,$end);
1.2 droeschl 50:
1.1 droeschl 51: if (defined($range)) {
1.2 droeschl 52: if ($range =~ /^(\d+)\-(\d+)$/) {
53: ($start,$end) = ($1,$2);
54: } elsif ($range =~/^(\d+)$/) {
55: ($start,$end) = (0,$1);
56: } else {
57: undef($range);
58: }
59: }
60:
61: my $hashref = &tie_user_hash($udom, $uname, $namespace, &GDBM_READER()) or
62: return "error: ".($!+0)." tie(GDBM) Failed while attempting dump";
63:
64: my $qresult = '';
65: my $count = 0;
1.1 droeschl 66: #
67: # When dump is for roles.db, determine if LON-CAPA version checking is needed.
1.2 droeschl 68: # Sessions on 2.10 and later do not require version checking, as that occurs
1.1 droeschl 69: # on the server hosting the user session, when constructing the roles/courses
70: # screen).
71: #
1.2 droeschl 72: my $skipcheck;
73: my @ids = &Apache::lonnet::current_machine_ids();
74: my (%homecourses, $major, $minor, $now);
1.1 droeschl 75: #
76: # If dump is for roles.db from a pre-2.10 server, determine the LON-CAPA
1.2 droeschl 77: # version on the server which requested the data.
1.1 droeschl 78: #
1.2 droeschl 79: if ($namespace eq 'roles') {
80: if ($clientversion =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?/) {
81: $major = $1;
82: $minor = $2;
1.4 ! droeschl 83:
1.2 droeschl 84: }
85: if (($major > 2) || (($major == 2) && ($minor > 9))) {
86: $skipcheck = 1;
1.1 droeschl 87: }
1.2 droeschl 88: $now = time;
89: }
90: while (my ($key,$value) = each(%$hashref)) {
91: if ($namespace eq 'roles' && (!$skipcheck)) {
1.1 droeschl 92: if ($key =~ m{^/($LONCAPA::match_domain)/($LONCAPA::match_courseid)(/?[^_]*)_(cc|co|in|ta|ep|ad|st|cr)$}) {
93: my $cdom = $1;
94: my $cnum = $2;
1.2 droeschl 95: my ($role,$roleend,$rolestart) = split(/\_/,$value);
96: if (!$roleend || $roleend > $now) {
1.1 droeschl 97: #
98: # For active course roles, check that requesting server is running a LON-CAPA
99: # version which meets any version requirements for the course. Do not include
100: # the role amongst the results returned if the requesting server's version is
101: # too old.
102: #
103: # This determination is handled differently depending on whether the course's
104: # homeserver is the current server, or whether it is a different server.
105: # In both cases, the course's version requirement needs to be retrieved.
106: #
1.2 droeschl 107: next unless (&releasereqd_check($cnum,$cdom,$key,$value,$major,
108: $minor,\%homecourses,\@ids));
1.1 droeschl 109: }
110: }
111: }
1.2 droeschl 112: if ($regexp eq '.') {
113: $count++;
114: if (defined($range) && $count >= $end) { last; }
115: if (defined($range) && $count < $start) { next; }
116: $qresult.=$key.'='.$value.'&';
117: } else {
118: my $unescapeKey = &unescape($key);
119: if (eval('$unescapeKey=~/$regexp/')) {
120: $count++;
121: if (defined($range) && $count >= $end) { last; }
122: if (defined($range) && $count < $start) { next; }
123: $qresult.="$key=$value&";
124: }
125: }
126: }
127:
128: &untie_user_hash($hashref) or
129: return "error: ".($!+0)." untie(GDBM) Failed while attempting dump";
1.1 droeschl 130: #
131: # If dump is for roles.db from a pre-2.10 server, check if the LON-CAPA
132: # version requirements for courses for which the current server is the home
133: # server permit course roles to be usable on the client server hosting the
134: # user's session. If so, include those role results in the data returned to
135: # the client server.
136: #
1.2 droeschl 137: if (($namespace eq 'roles') && (!$skipcheck)) {
138: if (keys(%homecourses) > 0) {
139: $qresult .= &check_homecourses(\%homecourses,$regexp,$count,
140: $range,$start,$end,$major,$minor);
141: }
142: }
143: chop($qresult);
144: return $qresult;
145: }
146:
147:
148: sub releasereqd_check {
149: my ($cnum,$cdom,$key,$value,$major,$minor,$homecourses,$ids) = @_;
150: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
151: return if ($home eq 'no_host');
152: my ($reqdmajor,$reqdminor,$displayrole);
153: if ($cnum =~ /$LONCAPA::match_community/) {
154: if ($major eq '' && $minor eq '') {
155: return unless ((ref($ids) eq 'ARRAY') &&
156: (grep(/^\Q$home\E$/,@{$ids})));
157: } else {
158: $reqdmajor = 2;
159: $reqdminor = 9;
160: return unless (&useable_role($reqdmajor,$reqdminor,$major,$minor));
161: }
162: }
163: my $hashid = $cdom.':'.$cnum;
164: my ($courseinfo,$cached) =
165: &Apache::lonnet::is_cached_new('courseinfo',$hashid);
166: if (defined($cached)) {
167: if (ref($courseinfo) eq 'HASH') {
168: if (exists($courseinfo->{'releaserequired'})) {
169: my ($reqdmajor,$reqdminor) = split(/\./,$courseinfo->{'releaserequired'});
170: return unless (&useable_role($reqdmajor,$reqdminor,$major,$minor));
171: }
172: }
173: } else {
174: if (ref($ids) eq 'ARRAY') {
175: if (grep(/^\Q$home\E$/,@{$ids})) {
176: if (ref($homecourses) eq 'HASH') {
177: if (ref($homecourses->{$cdom}) eq 'HASH') {
178: if (ref($homecourses->{$cdom}{$cnum}) eq 'HASH') {
179: if (ref($homecourses->{$cdom}{$cnum}) eq 'ARRAY') {
180: push(@{$homecourses->{$cdom}{$cnum}},{$key=>$value});
181: } else {
182: $homecourses->{$cdom}{$cnum} = [{$key=>$value}];
183: }
184: } else {
185: $homecourses->{$cdom}{$cnum} = [{$key=>$value}];
186: }
187: } else {
188: $homecourses->{$cdom}{$cnum} = [{$key=>$value}];
189: }
190: }
191: return;
192: }
193: }
194: my $courseinfo = &get_courseinfo_hash($cnum,$cdom,$home);
195: if (ref($courseinfo) eq 'HASH') {
196: if (exists($courseinfo->{'releaserequired'})) {
197: my ($reqdmajor,$reqdminor) = split(/\./,$courseinfo->{'releaserequired'});
198: return unless (&useable_role($reqdmajor,$reqdminor,$major,$minor));
199: }
200: } else {
201: return;
202: }
203: }
204: return 1;
205: }
206:
207:
208: sub check_homecourses {
209: my ($homecourses,$regexp,$count,$range,$start,$end,$major,$minor) = @_;
210: my ($result,%addtocache);
211: my $yesterday = time - 24*3600;
212: if (ref($homecourses) eq 'HASH') {
213: my (%okcourses,%courseinfo,%recent);
214: foreach my $domain (keys(%{$homecourses})) {
215: my $hashref =
216: &tie_domain_hash($domain, "nohist_courseids", &GDBM_WRCREAT());
217: if (ref($hashref) eq 'HASH') {
218: while (my ($key,$value) = each(%$hashref)) {
219: my $unesc_key = &unescape($key);
220: if ($unesc_key =~ /^lasttime:(\w+)$/) {
221: my $cid = $1;
222: $cid =~ s/_/:/;
223: if ($value > $yesterday ) {
224: $recent{$cid} = 1;
225: }
226: next;
227: }
228: my $items = &Apache::lonnet::thaw_unescape($value);
229: if (ref($items) eq 'HASH') {
230: my ($cdom,$cnum) = split(/_/,$unesc_key);
231: my $hashid = $cdom.':'.$cnum;
232: $courseinfo{$hashid} = $items;
233: if (ref($homecourses->{$cdom}{$cnum}) eq 'ARRAY') {
234: my ($reqdmajor,$reqdminor) = split(/\./,$items->{'releaserequired'});
235: if (&useable_role($reqdmajor,$reqdminor,$major,$minor)) {
236: $okcourses{$hashid} = 1;
237: }
238: }
239: }
240: }
241: unless (&untie_domain_hash($hashref)) {
242: &logthis("Failed to untie tied hash for nohist_courseids.db for $domain");
243: }
244: } else {
245: &logthis("Failed to tie hash for nohist_courseids.db for $domain");
246: }
247: }
248: foreach my $hashid (keys(%recent)) {
249: my ($result,$cached)=&Apache::lonnet::is_cached_new('courseinfo',$hashid);
250: unless ($cached) {
251: &Apache::lonnet::do_cache_new('courseinfo',$hashid,$courseinfo{$hashid},600);
252: }
253: }
254: foreach my $cdom (keys(%{$homecourses})) {
255: if (ref($homecourses->{$cdom}) eq 'HASH') {
256: foreach my $cnum (keys(%{$homecourses->{$cdom}})) {
257: my $hashid = $cdom.':'.$cnum;
258: next if ($recent{$hashid});
259: &Apache::lonnet::do_cache_new('courseinfo',$hashid,$courseinfo{$hashid},600);
260: }
261: }
262: }
263: foreach my $hashid (keys(%okcourses)) {
264: my ($cdom,$cnum) = split(/:/,$hashid);
265: if ((ref($homecourses->{$cdom}) eq 'HASH') &&
266: (ref($homecourses->{$cdom}{$cnum}) eq 'ARRAY')) {
267: foreach my $role (@{$homecourses->{$cdom}{$cnum}}) {
268: if (ref($role) eq 'HASH') {
269: while (my ($key,$value) = each(%{$role})) {
270: if ($regexp eq '.') {
271: $count++;
272: if (defined($range) && $count >= $end) { last; }
273: if (defined($range) && $count < $start) { next; }
274: $result.=$key.'='.$value.'&';
275: } else {
276: my $unescapeKey = &unescape($key);
277: if (eval('$unescapeKey=~/$regexp/')) {
278: $count++;
279: if (defined($range) && $count >= $end) { last; }
280: if (defined($range) && $count < $start) { next; }
281: $result.="$key=$value&";
282: }
283: }
284: }
285: }
1.1 droeschl 286: }
287: }
1.2 droeschl 288: }
1.1 droeschl 289: }
1.2 droeschl 290: return $result;
291: }
292:
1.1 droeschl 293:
1.2 droeschl 294: sub useable_role {
295: my ($reqdmajor,$reqdminor,$major,$minor) = @_;
296: if ($reqdmajor ne '' && $reqdminor ne '') {
297: return if (($major eq '' && $minor eq '') ||
298: ($major < $reqdmajor) ||
299: (($major == $reqdmajor) && ($minor < $reqdminor)));
300: }
1.1 droeschl 301: return 1;
302: }
303:
1.2 droeschl 304:
1.3 droeschl 305: sub get_courseinfo_hash {
306: my ($cnum,$cdom,$home) = @_;
307: my %info;
308: eval {
309: local($SIG{ALRM}) = sub { die "timeout\n"; };
310: local($SIG{__DIE__})='DEFAULT';
311: alarm(3);
312: %info = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,1,[$home],'.');
313: alarm(0);
314: };
315: if ($@) {
316: if ($@ eq "timeout\n") {
317: &logthis("<font color='blue'>WARNING courseiddump for $cnum:$cdom from $home timedout</font>");
318: } else {
319: &logthis("<font color='yellow'>WARNING unexpected error during eval of call for courseiddump from $home</font>");
320: }
321: } else {
322: if (ref($info{$cdom.'_'.$cnum}) eq 'HASH') {
323: my $hashid = $cdom.':'.$cnum;
324: return &Apache::lonnet::do_cache_new('courseinfo',$hashid,$info{$cdom.'_'.$cnum},600);
325: }
326: }
327: return;
328: }
1.2 droeschl 329:
1.4 ! droeschl 330: sub dump_course_id_handler {
! 331: my ($tail) = @_;
! 332:
! 333: my ($udom,$since,$description,$instcodefilter,$ownerfilter,$coursefilter,
! 334: $typefilter,$regexp_ok,$rtn_as_hash,$selfenrollonly,$catfilter,$showhidden,
! 335: $caller,$cloner,$cc_clone_list,$cloneonly,$createdbefore,$createdafter,
! 336: $creationcontext,$domcloner) = split(/:/,$tail);
! 337: my $now = time;
! 338: my ($cloneruname,$clonerudom,%cc_clone);
! 339: if (defined($description)) {
! 340: $description=&unescape($description);
! 341: } else {
! 342: $description='.';
! 343: }
! 344: if (defined($instcodefilter)) {
! 345: $instcodefilter=&unescape($instcodefilter);
! 346: } else {
! 347: $instcodefilter='.';
! 348: }
! 349: my ($ownerunamefilter,$ownerdomfilter);
! 350: if (defined($ownerfilter)) {
! 351: $ownerfilter=&unescape($ownerfilter);
! 352: if ($ownerfilter ne '.' && defined($ownerfilter)) {
! 353: if ($ownerfilter =~ /^([^:]*):([^:]*)$/) {
! 354: $ownerunamefilter = $1;
! 355: $ownerdomfilter = $2;
! 356: } else {
! 357: $ownerunamefilter = $ownerfilter;
! 358: $ownerdomfilter = '';
! 359: }
! 360: }
! 361: } else {
! 362: $ownerfilter='.';
! 363: }
! 364:
! 365: if (defined($coursefilter)) {
! 366: $coursefilter=&unescape($coursefilter);
! 367: } else {
! 368: $coursefilter='.';
! 369: }
! 370: if (defined($typefilter)) {
! 371: $typefilter=&unescape($typefilter);
! 372: } else {
! 373: $typefilter='.';
! 374: }
! 375: if (defined($regexp_ok)) {
! 376: $regexp_ok=&unescape($regexp_ok);
! 377: }
! 378: if (defined($catfilter)) {
! 379: $catfilter=&unescape($catfilter);
! 380: }
! 381: if (defined($cloner)) {
! 382: $cloner = &unescape($cloner);
! 383: ($cloneruname,$clonerudom) = ($cloner =~ /^($LONCAPA::match_username):($LONCAPA::match_domain)$/);
! 384: }
! 385: if (defined($cc_clone_list)) {
! 386: $cc_clone_list = &unescape($cc_clone_list);
! 387: my @cc_cloners = split('&',$cc_clone_list);
! 388: foreach my $cid (@cc_cloners) {
! 389: my ($clonedom,$clonenum) = split(':',$cid);
! 390: next if ($clonedom ne $udom);
! 391: $cc_clone{$clonedom.'_'.$clonenum} = 1;
! 392: }
! 393: }
! 394: if ($createdbefore ne '') {
! 395: $createdbefore = &unescape($createdbefore);
! 396: } else {
! 397: $createdbefore = 0;
! 398: }
! 399: if ($createdafter ne '') {
! 400: $createdafter = &unescape($createdafter);
! 401: } else {
! 402: $createdafter = 0;
! 403: }
! 404: if ($creationcontext ne '') {
! 405: $creationcontext = &unescape($creationcontext);
! 406: } else {
! 407: $creationcontext = '.';
! 408: }
! 409: my $unpack = 1;
! 410: if ($description eq '.' && $instcodefilter eq '.' && $ownerfilter eq '.' &&
! 411: $typefilter eq '.') {
! 412: $unpack = 0;
! 413: }
! 414: if (!defined($since)) { $since=0; }
! 415: my $qresult='';
! 416:
! 417: my $hashref = &tie_domain_hash($udom, "nohist_courseids", &GDBM_WRCREAT())
! 418: or return "error: ".($!+0)." tie(GDBM) Failed while attempting courseiddump";
! 419:
! 420: while (my ($key,$value) = each(%$hashref)) {
! 421: my ($unesc_key,$lasttime_key,$lasttime,$is_hash,%val,
! 422: %unesc_val,$selfenroll_end,$selfenroll_types,$created,
! 423: $context);
! 424: $unesc_key = &unescape($key);
! 425: if ($unesc_key =~ /^lasttime:/) {
! 426: next;
! 427: } else {
! 428: $lasttime_key = &escape('lasttime:'.$unesc_key);
! 429: }
! 430: if ($hashref->{$lasttime_key} ne '') {
! 431: $lasttime = $hashref->{$lasttime_key};
! 432: next if ($lasttime<$since);
! 433: }
! 434: my ($canclone,$valchange);
! 435: my $items = &Apache::lonnet::thaw_unescape($value);
! 436: if (ref($items) eq 'HASH') {
! 437: if ($hashref->{$lasttime_key} eq '') {
! 438: next if ($since > 1);
! 439: }
! 440: $is_hash = 1;
! 441: if ($domcloner) {
! 442: $canclone = 1;
! 443: } elsif (defined($clonerudom)) {
! 444: if ($items->{'cloners'}) {
! 445: my @cloneable = split(',',$items->{'cloners'});
! 446: if (@cloneable) {
! 447: if (grep(/^\*$/,@cloneable)) {
! 448: $canclone = 1;
! 449: } elsif (grep(/^\*:\Q$clonerudom\E$/,@cloneable)) {
! 450: $canclone = 1;
! 451: } elsif (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
! 452: $canclone = 1;
! 453: }
! 454: }
! 455: unless ($canclone) {
! 456: if ($cloneruname ne '' && $clonerudom ne '') {
! 457: if ($cc_clone{$unesc_key}) {
! 458: $canclone = 1;
! 459: $items->{'cloners'} .= ','.$cloneruname.':'.
! 460: $clonerudom;
! 461: $valchange = 1;
! 462: }
! 463: }
! 464: }
! 465: } elsif (defined($cloneruname)) {
! 466: if ($cc_clone{$unesc_key}) {
! 467: $canclone = 1;
! 468: $items->{'cloners'} = $cloneruname.':'.$clonerudom;
! 469: $valchange = 1;
! 470: }
! 471: unless ($canclone) {
! 472: if ($items->{'owner'} =~ /:/) {
! 473: if ($items->{'owner'} eq $cloner) {
! 474: $canclone = 1;
! 475: }
! 476: } elsif ($cloner eq $items->{'owner'}.':'.$udom) {
! 477: $canclone = 1;
! 478: }
! 479: if ($canclone) {
! 480: $items->{'cloners'} = $cloneruname.':'.$clonerudom;
! 481: $valchange = 1;
! 482: }
! 483: }
! 484: }
! 485: }
! 486: if ($unpack || !$rtn_as_hash) {
! 487: $unesc_val{'descr'} = $items->{'description'};
! 488: $unesc_val{'inst_code'} = $items->{'inst_code'};
! 489: $unesc_val{'owner'} = $items->{'owner'};
! 490: $unesc_val{'type'} = $items->{'type'};
! 491: $unesc_val{'cloners'} = $items->{'cloners'};
! 492: $unesc_val{'created'} = $items->{'created'};
! 493: $unesc_val{'context'} = $items->{'context'};
! 494: }
! 495: $selfenroll_types = $items->{'selfenroll_types'};
! 496: $selfenroll_end = $items->{'selfenroll_end_date'};
! 497: $created = $items->{'created'};
! 498: $context = $items->{'context'};
! 499: if ($selfenrollonly) {
! 500: next if (!$selfenroll_types);
! 501: if (($selfenroll_end > 0) && ($selfenroll_end <= $now)) {
! 502: next;
! 503: }
! 504: }
! 505: if ($creationcontext ne '.') {
! 506: next if (($context ne '') && ($context ne $creationcontext));
! 507: }
! 508: if ($createdbefore > 0) {
! 509: next if (($created eq '') || ($created > $createdbefore));
! 510: }
! 511: if ($createdafter > 0) {
! 512: next if (($created eq '') || ($created <= $createdafter));
! 513: }
! 514: if ($catfilter ne '') {
! 515: next if ($items->{'categories'} eq '');
! 516: my @categories = split('&',$items->{'categories'});
! 517: next if (@categories == 0);
! 518: my @subcats = split('&',$catfilter);
! 519: my $matchcat = 0;
! 520: foreach my $cat (@categories) {
! 521: if (grep(/^\Q$cat\E$/,@subcats)) {
! 522: $matchcat = 1;
! 523: last;
! 524: }
! 525: }
! 526: next if (!$matchcat);
! 527: }
! 528: if ($caller eq 'coursecatalog') {
! 529: if ($items->{'hidefromcat'} eq 'yes') {
! 530: next if !$showhidden;
! 531: }
! 532: }
! 533: } else {
! 534: next if ($catfilter ne '');
! 535: next if ($selfenrollonly);
! 536: next if ($createdbefore || $createdafter);
! 537: next if ($creationcontext ne '.');
! 538: if ((defined($clonerudom)) && (defined($cloneruname))) {
! 539: if ($cc_clone{$unesc_key}) {
! 540: $canclone = 1;
! 541: $val{'cloners'} = &escape($cloneruname.':'.$clonerudom);
! 542: }
! 543: }
! 544: $is_hash = 0;
! 545: my @courseitems = split(/:/,$value);
! 546: $lasttime = pop(@courseitems);
! 547: if ($hashref->{$lasttime_key} eq '') {
! 548: next if ($lasttime<$since);
! 549: }
! 550: ($val{'descr'},$val{'inst_code'},$val{'owner'},$val{'type'}) = @courseitems;
! 551: }
! 552: if ($cloneonly) {
! 553: next unless ($canclone);
! 554: }
! 555: my $match = 1;
! 556: if ($description ne '.') {
! 557: if (!$is_hash) {
! 558: $unesc_val{'descr'} = &unescape($val{'descr'});
! 559: }
! 560: if (eval{$unesc_val{'descr'} !~ /\Q$description\E/i}) {
! 561: $match = 0;
! 562: }
! 563: }
! 564: if ($instcodefilter ne '.') {
! 565: if (!$is_hash) {
! 566: $unesc_val{'inst_code'} = &unescape($val{'inst_code'});
! 567: }
! 568: if ($regexp_ok == 1) {
! 569: if (eval{$unesc_val{'inst_code'} !~ /$instcodefilter/}) {
! 570: $match = 0;
! 571: }
! 572: } elsif ($regexp_ok == -1) {
! 573: if (eval{$unesc_val{'inst_code'} =~ /$instcodefilter/}) {
! 574: $match = 0;
! 575: }
! 576: } else {
! 577: if (eval{$unesc_val{'inst_code'} !~ /\Q$instcodefilter\E/i}) {
! 578: $match = 0;
! 579: }
! 580: }
! 581: }
! 582: if ($ownerfilter ne '.') {
! 583: if (!$is_hash) {
! 584: $unesc_val{'owner'} = &unescape($val{'owner'});
! 585: }
! 586: if (($ownerunamefilter ne '') && ($ownerdomfilter ne '')) {
! 587: if ($unesc_val{'owner'} =~ /:/) {
! 588: if (eval{$unesc_val{'owner'} !~
! 589: /\Q$ownerunamefilter\E:\Q$ownerdomfilter\E$/i}) {
! 590: $match = 0;
! 591: }
! 592: } else {
! 593: if (eval{$unesc_val{'owner'} !~ /\Q$ownerunamefilter\E/i}) {
! 594: $match = 0;
! 595: }
! 596: }
! 597: } elsif ($ownerunamefilter ne '') {
! 598: if ($unesc_val{'owner'} =~ /:/) {
! 599: if (eval{$unesc_val{'owner'} !~ /\Q$ownerunamefilter\E:[^:]+$/i}) {
! 600: $match = 0;
! 601: }
! 602: } else {
! 603: if (eval{$unesc_val{'owner'} !~ /\Q$ownerunamefilter\E/i}) {
! 604: $match = 0;
! 605: }
! 606: }
! 607: } elsif ($ownerdomfilter ne '') {
! 608: if ($unesc_val{'owner'} =~ /:/) {
! 609: if (eval{$unesc_val{'owner'} !~ /^[^:]+:\Q$ownerdomfilter\E/}) {
! 610: $match = 0;
! 611: }
! 612: } else {
! 613: if ($ownerdomfilter ne $udom) {
! 614: $match = 0;
! 615: }
! 616: }
! 617: }
! 618: }
! 619: if ($coursefilter ne '.') {
! 620: if (eval{$unesc_key !~ /^$udom(_)\Q$coursefilter\E$/}) {
! 621: $match = 0;
! 622: }
! 623: }
! 624: if ($typefilter ne '.') {
! 625: if (!$is_hash) {
! 626: $unesc_val{'type'} = &unescape($val{'type'});
! 627: }
! 628: if ($unesc_val{'type'} eq '') {
! 629: if ($typefilter ne 'Course') {
! 630: $match = 0;
! 631: }
! 632: } else {
! 633: if (eval{$unesc_val{'type'} !~ /^\Q$typefilter\E$/}) {
! 634: $match = 0;
! 635: }
! 636: }
! 637: }
! 638: if ($match == 1) {
! 639: if ($rtn_as_hash) {
! 640: if ($is_hash) {
! 641: if ($valchange) {
! 642: my $newvalue = &Apache::lonnet::freeze_escape($items);
! 643: $qresult.=$key.'='.$newvalue.'&';
! 644: } else {
! 645: $qresult.=$key.'='.$value.'&';
! 646: }
! 647: } else {
! 648: my %rtnhash = ( 'description' => &unescape($val{'descr'}),
! 649: 'inst_code' => &unescape($val{'inst_code'}),
! 650: 'owner' => &unescape($val{'owner'}),
! 651: 'type' => &unescape($val{'type'}),
! 652: 'cloners' => &unescape($val{'cloners'}),
! 653: );
! 654: my $items = &Apache::lonnet::freeze_escape(\%rtnhash);
! 655: $qresult.=$key.'='.$items.'&';
! 656: }
! 657: } else {
! 658: if ($is_hash) {
! 659: $qresult .= $key.'='.&escape($unesc_val{'descr'}).':'.
! 660: &escape($unesc_val{'inst_code'}).':'.
! 661: &escape($unesc_val{'owner'}).'&';
! 662: } else {
! 663: $qresult .= $key.'='.$val{'descr'}.':'.$val{'inst_code'}.
! 664: ':'.$val{'owner'}.'&';
! 665: }
! 666: }
! 667: }
! 668: }
! 669: &untie_domain_hash($hashref) or
! 670: return "error: ".($!+0)." untie(GDBM) Failed while attempting courseiddump";
! 671:
! 672: chop($qresult);
! 673: return $qresult;
! 674: }
! 675:
! 676: sub dump_profile_database {
! 677: my ($tail) = @_;
! 678:
! 679: my ($udom,$uname,$namespace) = split(/:/,$tail);
! 680:
! 681: my $hashref = &tie_user_hash($udom, $uname, $namespace, &GDBM_READER()) or
! 682: return "error: ".($!+0)." tie(GDBM) Failed while attempting currentdump";
! 683:
! 684: # Structure of %data:
! 685: # $data{$symb}->{$parameter}=$value;
! 686: # $data{$symb}->{'v.'.$parameter}=$version;
! 687: # since $parameter will be unescaped, we do not
! 688: # have to worry about silly parameter names...
! 689:
! 690: my $qresult='';
! 691: my %data = (); # A hash of anonymous hashes..
! 692: while (my ($key,$value) = each(%$hashref)) {
! 693: my ($v,$symb,$param) = split(/:/,$key);
! 694: next if ($v eq 'version' || $symb eq 'keys');
! 695: next if (exists($data{$symb}) &&
! 696: exists($data{$symb}->{$param}) &&
! 697: $data{$symb}->{'v.'.$param} > $v);
! 698: $data{$symb}->{$param}=$value;
! 699: $data{$symb}->{'v.'.$param}=$v;
! 700: }
! 701:
! 702: &untie_user_hash($hashref) or
! 703: return "error: ".($!+0)." untie(GDBM) Failed while attempting currentdump";
! 704:
! 705: while (my ($symb,$param_hash) = each(%data)) {
! 706: while(my ($param,$value) = each (%$param_hash)){
! 707: next if ($param =~ /^v\./); # Ignore versions...
! 708: #
! 709: # Just dump the symb=value pairs separated by &
! 710: #
! 711: $qresult.=$symb.':'.$param.'='.$value.'&';
! 712: }
! 713: }
1.2 droeschl 714:
1.4 ! droeschl 715: chop($qresult);
! 716: return $qresult;
! 717: }
1.2 droeschl 718:
719:
1.1 droeschl 720: 1;
721:
722: __END__
723:
724: =head1 NAME
725:
726: LONCAPA::Lond.pm
727:
728: =head1 SYNOPSIS
729:
730: #TODO
731:
732: =head1 DESCRIPTION
733:
734: #TODO
735:
736: =head1 METHODS
737:
738: =over 4
739:
1.2 droeschl 740: =item dump_with_regexp( $tail, $client )
1.1 droeschl 741:
742: Dump a profile database with an optional regular expression to match against
743: the keys. In this dump, no effort is made to separate symb from version
744: information. Presumably the databases that are dumped by this command are of a
745: different structure. Need to look at this and improve the documentation of
746: both this and the currentdump handler.
747:
748: $tail a colon separated list containing
749:
750: =over
751:
752: =item domain
753:
754: =item user
755:
756: identifying the user.
757:
758: =item namespace
759:
760: identifying the database.
761:
762: =item regexp
763:
764: optional regular expression that is matched against database keywords to do
765: selective dumps.
766:
767: =item range
768:
769: optional range of entries e.g., 10-20 would return the 10th to 19th items, etc.
770:
771: =back
772:
773: $client is the channel open on the client.
774:
775: Returns: 1 (Continue processing).
776:
777: Side effects: response is written to $client.
778:
1.4 ! droeschl 779: =item dump_couse_id_handler
! 780:
! 781: #TODO copy from lond
! 782:
! 783: =item dump_profile_database
! 784:
! 785: #TODO copy from lond
1.2 droeschl 786:
787: =item releasereqd_check( $cnum, $cdom, $key, $value, $major, $minor,
788: $homecourses, $ids )
789:
790: releasereqd_check() will determine if a LON-CAPA version (defined in the
791: $major,$minor args passed) is not too old to allow use of a role in a
792: course ($cnum,$cdom args passed), if at least one of the following applies:
793: (a) the course is a Community, (b) the course's home server is *not* the
794: current server, or (c) cached course information is not stale.
795:
796: For the case where none of these apply, the course is added to the
797: $homecourse hash ref (keys = courseIDs, values = array of a hash of roles).
798: The $homecourse hash ref is for courses for which the current server is the
799: home server. LON-CAPA version requirements are checked elsewhere for the
800: items in $homecourse.
801:
802:
803: =item check_homecourses( $homecourses, $regexp, $count, $range, $start, $end,
804: $major, $minor )
805:
806: check_homecourses() will retrieve course information for those courses which
807: are keys of the $homecourses hash ref (first arg). The nohist_courseids.db
808: GDBM file is tied and course information for each course retrieved. Last
809: visit (lasttime key) is also retrieved for each, and cached values updated
810: for any courses last visited less than 24 hours ago. Cached values are also
811: updated for any courses included in the $homecourses hash ref.
812:
813: The reason for the 24 hours constraint is that the cron entry in
814: /etc/cron.d/loncapa for /home/httpd/perl/refresh_courseids_db.pl causes
815: cached course information to be updated nightly for courses with activity
816: within the past 24 hours.
817:
818: Role information for the user (included in a ref to an array of hashes as the
819: value for each key in $homecourses) is appended to the result returned by the
820: routine, which will in turn be appended to the string returned to the client
821: hosting the user's session.
822:
823:
824: =item useable_role( $reqdmajor, $reqdminor, $major, $minor )
825:
826: useable_role() will compare the LON-CAPA version required by a course with
827: the version available on the client server. If the client server's version
828: is compatible, 1 will be returned.
829:
830:
1.3 droeschl 831: =item get_courseinfo_hash( $cnum, $cdom, $home )
832:
833: get_courseinfo_hash() is used to retrieve course information from the db
834: file: nohist_courseids.db for a course for which the current server is *not*
835: the home server.
836:
837: A hash of a hash will be retrieved. The outer hash contains a single key --
838: courseID -- for the course for which the data are being requested.
839: The contents of the inner hash, for that single item in the outer hash
840: are returned (and cached in memcache for 10 minutes).
841:
842:
843:
1.1 droeschl 844: =back
845:
846: =head1 BUGS
847:
848: No known bugs at this time.
849:
850: =head1 SEE ALSO
851:
852: L<Apache::lonnet>, L<lond>
853:
854: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>