Annotation of loncom/metadata_database/LONCAPA/lonmetadata.pm, revision 1.26
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.26 ! bisitz 3: # $Id: lonmetadata.pm,v 1.25 2007/12/07 22:31:08 raeburn Exp $
1.1 matthew 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: package LONCAPA::lonmetadata;
30:
31: use strict;
32: use DBI;
1.16 raeburn 33: use HTML::TokeParser;
1.14 raeburn 34: use vars qw($Metadata_Table_Description $Portfolio_metadata_table_description
1.23 raeburn 35: $Portfolio_access_table_description $Fulltext_indicies $Portfolio_metadata_indices $Portfolio_access_indices $Portfolio_addedfields_table_description $Portfolio_addedfields_indices $Allusers_table_description $Allusers_indices);
1.1 matthew 36:
37: ######################################################################
38: ######################################################################
39:
40: =pod
41:
42: =head1 Name
43:
44: lonmetadata
45:
46: =head1 Synopsis
47:
48: lonmetadata holds a description of the metadata table and provides
49: wrappers for the storage and retrieval of metadata to/from the database.
50:
51: =head1 Description
52:
53: =head1 Methods
54:
55: =over 4
56:
57: =cut
58:
59: ######################################################################
60: ######################################################################
61:
62: =pod
63:
64: =item Old table creation command
65:
66: CREATE TABLE IF NOT EXISTS metadata
67: (title TEXT,
68: author TEXT,
69: subject TEXT,
70: url TEXT,
71: keywords TEXT,
72: version TEXT,
73: notes TEXT,
74: abstract TEXT,
75: mime TEXT,
76: language TEXT,
77: creationdate DATETIME,
78: lastrevisiondate DATETIME,
79: owner TEXT,
80: copyright TEXT,
1.12 matthew 81: domain TEXT
1.1 matthew 82:
83: FULLTEXT idx_title (title),
84: FULLTEXT idx_author (author),
85: FULLTEXT idx_subject (subject),
86: FULLTEXT idx_url (url),
87: FULLTEXT idx_keywords (keywords),
88: FULLTEXT idx_version (version),
89: FULLTEXT idx_notes (notes),
90: FULLTEXT idx_abstract (abstract),
91: FULLTEXT idx_mime (mime),
92: FULLTEXT idx_language (language),
93: FULLTEXT idx_owner (owner),
94: FULLTEXT idx_copyright (copyright))
95:
96: TYPE=MYISAM;
97:
98: =cut
99:
100: ######################################################################
101: ######################################################################
1.14 raeburn 102: $Metadata_Table_Description =
103: [
1.1 matthew 104: { name => 'title', type=>'TEXT'},
105: { name => 'author', type=>'TEXT'},
106: { name => 'subject', type=>'TEXT'},
107: { name => 'url', type=>'TEXT', restrictions => 'NOT NULL' },
108: { name => 'keywords', type=>'TEXT'},
109: { name => 'version', type=>'TEXT'},
110: { name => 'notes', type=>'TEXT'},
111: { name => 'abstract', type=>'TEXT'},
112: { name => 'mime', type=>'TEXT'},
113: { name => 'language', type=>'TEXT'},
114: { name => 'creationdate', type=>'DATETIME'},
115: { name => 'lastrevisiondate', type=>'DATETIME'},
116: { name => 'owner', type=>'TEXT'},
117: { name => 'copyright', type=>'TEXT'},
1.12 matthew 118: { name => 'domain', type=>'TEXT'},
1.1 matthew 119: #--------------------------------------------------
120: { name => 'dependencies', type=>'TEXT'},
121: { name => 'modifyinguser', type=>'TEXT'},
122: { name => 'authorspace', type=>'TEXT'},
123: { name => 'lowestgradelevel', type=>'INT'},
124: { name => 'highestgradelevel', type=>'INT'},
125: { name => 'standards', type=>'TEXT'},
126: { name => 'count', type=>'INT'},
127: { name => 'course', type=>'INT'},
128: { name => 'course_list', type=>'TEXT'},
129: { name => 'goto', type=>'INT'},
130: { name => 'goto_list', type=>'TEXT'},
131: { name => 'comefrom', type=>'INT'},
132: { name => 'comefrom_list', type=>'TEXT'},
133: { name => 'sequsage', type=>'INT'},
134: { name => 'sequsage_list', type=>'TEXT'},
135: { name => 'stdno', type=>'INT'},
136: { name => 'stdno_list', type=>'TEXT'},
137: { name => 'avetries', type=>'FLOAT'},
138: { name => 'avetries_list', type=>'TEXT'},
139: { name => 'difficulty', type=>'FLOAT'},
140: { name => 'difficulty_list',type=>'TEXT'},
1.9 matthew 141: { name => 'disc', type=>'FLOAT'},
142: { name => 'disc_list', type=>'TEXT'},
1.1 matthew 143: { name => 'clear', type=>'FLOAT'},
144: { name => 'technical', type=>'FLOAT'},
145: { name => 'correct', type=>'FLOAT'},
146: { name => 'helpful', type=>'FLOAT'},
147: { name => 'depth', type=>'FLOAT'},
148: { name => 'hostname', type=> 'TEXT'},
149: #--------------------------------------------------
1.14 raeburn 150: ];
1.1 matthew 151:
1.14 raeburn 152: $Fulltext_indicies = [ qw/
1.1 matthew 153: title
154: author
155: subject
156: url
157: keywords
158: version
159: notes
160: abstract
161: mime
162: language
163: owner
1.14 raeburn 164: copyright/ ];
165:
166: ######################################################################
167: ######################################################################
168: $Portfolio_metadata_table_description =
169: [
170: { name => 'title', type=>'TEXT'},
171: { name => 'author', type=>'TEXT'},
172: { name => 'subject', type=>'TEXT'},
173: { name => 'url', type=>'TEXT', restrictions => 'NOT NULL' },
174: { name => 'keywords', type=>'TEXT'},
175: { name => 'version', type=>'TEXT'},
176: { name => 'notes', type=>'TEXT'},
177: { name => 'abstract', type=>'TEXT'},
178: { name => 'mime', type=>'TEXT'},
179: { name => 'language', type=>'TEXT'},
180: { name => 'creationdate', type=>'DATETIME'},
181: { name => 'lastrevisiondate', type=>'DATETIME'},
182: { name => 'owner', type=>'TEXT'},
183: { name => 'copyright', type=>'TEXT'},
184: { name => 'domain', type=>'TEXT'},
185: { name => 'groupname', type=>'TEXT'},
186: { name => 'courserestricted', type=>'TEXT'},
187: #--------------------------------------------------
188: { name => 'dependencies', type=>'TEXT'},
189: { name => 'modifyinguser', type=>'TEXT'},
190: { name => 'authorspace', type=>'TEXT'},
191: { name => 'lowestgradelevel', type=>'INT'},
192: { name => 'highestgradelevel', type=>'INT'},
193: { name => 'standards', type=>'TEXT'},
194: { name => 'hostname', type=> 'TEXT'},
195: #--------------------------------------------------
196: ];
197:
198: $Portfolio_metadata_indices = [qw/
199: title
200: author
201: subject
202: url
203: keywords
204: version
205: notes
206: abstract
207: mime
208: language
209: owner/];
210:
211: ######################################################################
212: ######################################################################
213:
214: $Portfolio_access_table_description =
215: [
216: { name => 'url', type=>'TEXT', restrictions => 'NOT NULL' },
217: { name => 'keynum', type=>'TEXT', restrictions => 'NOT NULL' },
218: { name => 'scope', type=>'TEXT'},
219: { name => 'start', type=>'DATETIME'},
220: { name => 'end', type=>'DATETIME'},
221: ];
222:
223: $Portfolio_access_indices = [qw/
224: url
225: keynum
226: scope
227: start
228: end/];
1.1 matthew 229:
230: ######################################################################
231: ######################################################################
232:
1.14 raeburn 233: $Portfolio_addedfields_table_description =
234: [
235: { name => 'url', type=>'TEXT', restrictions => 'NOT NULL' },
236: { name => 'field', type=>'TEXT', restrictions => 'NOT NULL' },
237: { name => 'courserestricted', type=>'TEXT', restrictions => 'NOT NULL' },
238: { name => 'value', type=>'TEXT'},
239: ];
240:
241: $Portfolio_addedfields_indices = [qw/
242: url
243: field
244: value
245: courserestricted/];
246:
247: ######################################################################
248: ######################################################################
249:
1.23 raeburn 250: $Allusers_table_description =
251: [
252: { name => 'username', type=>'TEXT', restrictions => 'NOT NULL' },
253: { name => 'domain', type=>'TEXT', restrictions => 'NOT NULL' },
254: { name => 'lastname', type=>'TEXT',},
255: { name => 'firstname', type=>'TEXT'},
256: { name => 'middlename', type=>'TEXT'},
257: { name => 'generation', type=>'TEXT'},
258: { name => 'permanentemail', type=>'TEXT'},
259: { name => 'id', type=>'TEXT'},
260: ];
261:
262: $Allusers_indices = [qw/
263: username
264: domain
265: lastname
266: firstname/];
267:
268: ######################################################################
269: ######################################################################
1.14 raeburn 270:
1.1 matthew 271: =pod
272:
273: =item &describe_metadata_storage
274:
275: Input: None
276:
1.2 matthew 277: Returns: An array of hash references describing the columns and indicies
278: of the metadata table(s).
1.1 matthew 279:
280: =cut
281:
282: ######################################################################
283: ######################################################################
1.14 raeburn 284: sub describe_metadata_storage {
285: my ($tabletype) = @_;
286: my %table_description = (
287: metadata => $Metadata_Table_Description,
288: portfolio_metadata => $Portfolio_metadata_table_description,
289: portfolio_access => $Portfolio_access_table_description,
290: portfolio_addedfields => $Portfolio_addedfields_table_description,
1.23 raeburn 291: allusers => $Allusers_table_description,
1.14 raeburn 292: );
293: my %index_description = (
294: metadata => $Fulltext_indicies,
295: portfolio_metadata => $Portfolio_metadata_indices,
296: portfolio_access => $Portfolio_access_indices,
297: portfolio_addedfields => $Portfolio_addedfields_indices,
1.23 raeburn 298: allusers => $Allusers_indices,
1.14 raeburn 299: );
300: if ($tabletype eq 'portfolio_search') {
301: my @portfolio_search_table = @{$table_description{portfolio_metadata}};
302: foreach my $item (@{$table_description{portfolio_access}}) {
303: if (ref($item) eq 'HASH') {
304: if ($item->{'name'} eq 'url') {
305: next;
306: }
307: }
308: push(@portfolio_search_table,$item);
309: }
310: my @portfolio_search_indices = @{$index_description{portfolio_metadata}};
311: push(@portfolio_search_indices,('scope','keynum'));
312: return (\@portfolio_search_table,\@portfolio_search_indices);
313: } else {
314: return ($table_description{$tabletype},$index_description{$tabletype});
315: }
1.1 matthew 316: }
317:
318: ######################################################################
319: ######################################################################
320:
321: =pod
322:
323: =item create_metadata_storage()
324:
1.3 matthew 325: Inputs: table name (optional): the name of the table. Default is 'metadata'.
1.1 matthew 326:
327: Returns: A perl string which, when executed by MySQL, will cause the
328: metadata storage to be initialized.
329:
330: =cut
331:
332: ######################################################################
333: ######################################################################
334: sub create_metadata_storage {
1.14 raeburn 335: my ($tablename,$tabletype) = @_;
1.3 matthew 336: $tablename = 'metadata' if (! defined($tablename));
1.14 raeburn 337: $tabletype = 'metadata' if (! defined($tabletype));
1.1 matthew 338: my $request = "CREATE TABLE IF NOT EXISTS ".$tablename." ";
339: #
340: # Process the columns (this code is stolen from lonmysql.pm)
341: my @Columns;
342: my $col_des; # mysql column description
1.14 raeburn 343: my ($table_columns,$table_indices) =
344: &describe_metadata_storage($tabletype);
345: my %coltype;
346: foreach my $coldata (@{$table_columns}) {
1.1 matthew 347: my $column = $coldata->{'name'};
1.14 raeburn 348: $coltype{$column} = $coldata->{'type'};
1.1 matthew 349: $col_des = '';
350: if (lc($coldata->{'type'}) =~ /(enum|set)/) { # 'enum' or 'set'
351: $col_des.=$column." ".$coldata->{'type'}."('".
352: join("', '",@{$coldata->{'values'}})."')";
353: } else {
354: $col_des.=$column." ".$coldata->{'type'};
355: if (exists($coldata->{'size'})) {
356: $col_des.="(".$coldata->{'size'}.")";
357: }
358: }
359: # Modifiers
360: if (exists($coldata->{'restrictions'})){
361: $col_des.=" ".$coldata->{'restrictions'};
362: }
363: if (exists($coldata->{'default'})) {
364: $col_des.=" DEFAULT '".$coldata->{'default'}."'";
365: }
366: $col_des.=' AUTO_INCREMENT' if (exists($coldata->{'auto_inc'}) &&
367: ($coldata->{'auto_inc'} eq 'yes'));
368: $col_des.=' PRIMARY KEY' if (exists($coldata->{'primary_key'}) &&
369: ($coldata->{'primary_key'} eq 'yes'));
370: } continue {
371: # skip blank items.
372: push (@Columns,$col_des) if ($col_des ne '');
373: }
1.14 raeburn 374: foreach my $colname (@{$table_indices}) {
375: my $text;
376: if ($coltype{$colname} eq 'TEXT') {
377: $text = 'FULLTEXT ';
378: } else {
379: $text = 'INDEX ';
380: }
381: $text .= 'idx_'.$colname.' ('.$colname.')';
1.1 matthew 382: push (@Columns,$text);
383: }
1.3 matthew 384: $request .= "(".join(", ",@Columns).") TYPE=MyISAM";
1.1 matthew 385: return $request;
386: }
387:
388: ######################################################################
389: ######################################################################
390:
391: =pod
392:
393: =item store_metadata()
394:
1.14 raeburn 395: Inputs: database handle ($dbh), a table name, table type and a hash or hash
396: reference containing the metadata for a single resource.
1.1 matthew 397:
398: Returns: 1 on success, 0 on failure to store.
399:
400: =cut
401:
402: ######################################################################
403: ######################################################################
1.2 matthew 404: {
405: ##
406: ## WARNING: The following cleverness may cause trouble in cases where
407: ## the dbi connection is dropped and recreated - a stale statement
408: ## handler may linger around and cause trouble.
409: ##
410: ## In most scripts, this will work fine. If the dbi is going to be
411: ## dropped and (possibly) later recreated, call &clear_sth. Yes it
1.14 raeburn 412: ## is annoying but $sth apparently does not have a link back to the
1.2 matthew 413: ## $dbh, so we can't check our validity.
414: ##
415: my $sth = undef;
1.4 matthew 416: my $sth_table = undef;
1.2 matthew 417:
418: sub create_statement_handler {
1.14 raeburn 419: my ($dbh,$tablename,$tabletype) = @_;
1.4 matthew 420: $tablename = 'metadata' if (! defined($tablename));
1.14 raeburn 421: $tabletype = 'metadata' if (! defined($tabletype));
422: my ($table_columns,$table_indices) =
423: &describe_metadata_storage($tabletype);
1.4 matthew 424: $sth_table = $tablename;
425: my $request = 'INSERT INTO '.$tablename.' VALUES(';
1.14 raeburn 426: foreach (@{$table_columns}) {
1.2 matthew 427: $request .= '?,';
428: }
429: chop $request;
430: $request.= ')';
431: $sth = $dbh->prepare($request);
432: return;
433: }
434:
1.4 matthew 435: sub clear_sth { $sth=undef; $sth_table=undef;}
1.2 matthew 436:
1.1 matthew 437: sub store_metadata {
1.14 raeburn 438: my ($dbh,$tablename,$tabletype,@Metadata)=@_;
1.2 matthew 439: my $errors = '';
1.4 matthew 440: if (! defined($sth) ||
441: ( defined($tablename) && ($sth_table ne $tablename)) ||
442: (! defined($tablename) && $sth_table ne 'metadata')) {
1.14 raeburn 443: &create_statement_handler($dbh,$tablename,$tabletype);
1.2 matthew 444: }
445: my $successcount = 0;
1.14 raeburn 446: if (! defined($tabletype)) {
447: $tabletype = 'metadata';
448: }
449: my ($table_columns,$table_indices) =
450: &describe_metadata_storage($tabletype);
1.10 matthew 451: foreach my $mdata (@Metadata) {
1.2 matthew 452: next if (ref($mdata) ne "HASH");
453: my @MData;
1.14 raeburn 454: foreach my $field (@{$table_columns}) {
1.10 matthew 455: my $fname = $field->{'name'};
456: if (exists($mdata->{$fname}) &&
457: defined($mdata->{$fname}) &&
458: $mdata->{$fname} ne '') {
459: if ($mdata->{$fname} eq 'nan' ||
460: $mdata->{$fname} eq '') {
1.5 matthew 461: push(@MData,'NULL');
462: } else {
1.10 matthew 463: push(@MData,$mdata->{$fname});
1.5 matthew 464: }
1.2 matthew 465: } else {
466: push(@MData,undef);
467: }
468: }
469: $sth->execute(@MData);
470: if (! $sth->err) {
471: $successcount++;
472: } else {
473: $errors = join(',',$errors,$sth->errstr);
474: }
1.10 matthew 475: $errors =~ s/^,//;
1.2 matthew 476: }
477: if (wantarray()) {
478: return ($successcount,$errors);
479: } else {
480: return $successcount;
481: }
482: }
1.1 matthew 483:
484: }
485:
486: ######################################################################
487: ######################################################################
488:
489: =pod
490:
1.24 albertel 491: =item lookup_metadata()
1.1 matthew 492:
493: Inputs: database handle ($dbh) and a hash or hash reference containing
494: metadata which will be used for a search.
495:
1.2 matthew 496: Returns: scalar with error string on failure, array reference on success.
497: The array reference is the same one returned by $sth->fetchall_arrayref().
1.1 matthew 498:
499: =cut
500:
501: ######################################################################
502: ######################################################################
1.2 matthew 503: sub lookup_metadata {
1.10 matthew 504: my ($dbh,$condition,$fetchparameter,$tablename) = @_;
505: $tablename = 'metadata' if (! defined($tablename));
1.2 matthew 506: my $error;
507: my $returnvalue=[];
1.10 matthew 508: my $request = 'SELECT * FROM '.$tablename;
1.2 matthew 509: if (defined($condition)) {
510: $request .= ' WHERE '.$condition;
511: }
512: my $sth = $dbh->prepare($request);
513: if ($sth->err) {
514: $error = $sth->errstr;
515: }
516: if (! $error) {
517: $sth->execute();
518: if ($sth->err) {
519: $error = $sth->errstr;
520: } else {
521: $returnvalue = $sth->fetchall_arrayref($fetchparameter);
522: if ($sth->err) {
523: $error = $sth->errstr;
524: }
525: }
1.16 raeburn 526: }
1.2 matthew 527: return ($error,$returnvalue);
528: }
1.1 matthew 529:
530: ######################################################################
531: ######################################################################
532:
533: =pod
534:
535: =item delete_metadata()
536:
1.10 matthew 537: Removes a single metadata record, based on its url.
538:
539: Inputs: $dbh, the database handler.
540: $tablename, the name of the metadata table to remove from. default: 'metadata'
1.23 raeburn 541: $delitem, the resource to remove from the metadata database, in the form:
542: url = quoted url
1.10 matthew 543:
544: Returns: undef on success, dbh errorstr on failure.
545:
546: =cut
547:
548: ######################################################################
549: ######################################################################
550: sub delete_metadata {
1.23 raeburn 551: my ($dbh,$tablename,$delitem) = @_;
1.10 matthew 552: $tablename = 'metadata' if (! defined($tablename));
1.23 raeburn 553: my ($error,$delete_command);
554: if ($delitem eq '') {
555: $error = 'deletion aborted - no resource specified';
556: } else {
557: $delete_command = 'DELETE FROM '.$tablename.' WHERE '.$delitem;
558: $dbh->do($delete_command);
559: if ($dbh->err) {
560: $error = $dbh->errstr();
561: }
1.10 matthew 562: }
563: return $error;
564: }
565:
566: ######################################################################
567: ######################################################################
568:
569: =pod
570:
571: =item update_metadata
572:
573: Updates metadata record in mysql database. It does not matter if the record
574: currently exists. Fields not present in the new metadata will be taken
575: from the current record, if it exists. To delete an entry for a key, set
576: it to "" or undef.
577:
578: Inputs:
579: $dbh, database handle
580: $newmetadata, hash reference containing the new metadata
581: $tablename, metadata table name. Defaults to 'metadata'.
1.23 raeburn 582: $tabletype, type of table (metadata, portfolio_metadata, portfolio_access,
583: allusers)
584: $conditions, optional hash of conditions to use in SQL queries;
585: default used if none provided.
1.10 matthew 586:
587: Returns:
588: $error on failure. undef on success.
1.1 matthew 589:
590: =cut
591:
592: ######################################################################
593: ######################################################################
1.10 matthew 594: sub update_metadata {
1.23 raeburn 595: my ($dbh,$tablename,$tabletype,$newmetadata,$conditions)=@_;
596: my ($error,$condition);
1.10 matthew 597: $tablename = 'metadata' if (! defined($tablename));
1.14 raeburn 598: $tabletype = 'metadata' if (! defined($tabletype));
1.23 raeburn 599: if (ref($conditions) eq 'HASH') {
600: my @items;
601: foreach my $key (keys(%{$conditions})) {
602: if (! exists($newmetadata->{$key})) {
603: $error .= "Unable to update: no $key specified";
604: } else {
605: push(@items,"$key = ".$dbh->quote($newmetadata->{$key}));
606: }
607: }
608: $condition = join(' AND ',@items);
609: } else {
610: if (! exists($newmetadata->{'url'})) {
611: $error = 'Unable to update: no url specified';
612: } else {
613: $condition = 'url = '.$dbh->quote($newmetadata->{'url'});
614: }
1.10 matthew 615: }
616: return $error if (defined($error));
617: #
618: # Retrieve current values
619: my $row;
1.23 raeburn 620: ($error,$row) = &lookup_metadata($dbh,$condition,undef,$tablename);
1.10 matthew 621: return $error if ($error);
1.14 raeburn 622: my %metadata = &LONCAPA::lonmetadata::metadata_col_to_hash($tabletype,@{$row->[0]});
1.10 matthew 623: #
624: # Update metadata values
625: while (my ($key,$value) = each(%$newmetadata)) {
626: $metadata{$key} = $value;
627: }
628: #
629: # Delete old data (deleting a nonexistant record does not produce an error.
1.23 raeburn 630: $error = &delete_metadata($dbh,$tablename,$condition);
1.10 matthew 631: return $error if (defined($error));
632: #
633: # Store updated metadata
634: my $success;
1.14 raeburn 635: ($success,$error) = &store_metadata($dbh,$tablename,$tabletype,\%metadata);
1.10 matthew 636: return $error;
637: }
1.1 matthew 638:
639: ######################################################################
640: ######################################################################
1.5 matthew 641:
1.6 matthew 642: =pod
643:
644: =item metdata_col_to_hash
645:
646: Input: Array of metadata columns
647:
648: Return: Hash with the metadata columns as keys and the array elements
649: passed in as values
650:
651: =cut
652:
653: ######################################################################
654: ######################################################################
655: sub metadata_col_to_hash {
1.14 raeburn 656: my ($tabletype,@cols)=@_;
1.6 matthew 657: my %hash=();
1.14 raeburn 658: my ($columns,$indices) = &describe_metadata_storage($tabletype);
659: for (my $i=0; $i<@{$columns};$i++) {
660: $hash{$columns->[$i]->{'name'}}=$cols[$i];
661: unless ($hash{$columns->[$i]->{'name'}}) {
662: if ($columns->[$i]->{'type'} eq 'TEXT') {
663: $hash{$columns->[$i]->{'name'}}='';
664: } elsif ($columns->[$i]->{'type'} eq 'DATETIME') {
665: $hash{$columns->[$i]->{'name'}}='0000-00-00 00:00:00';
1.13 www 666: } else {
1.14 raeburn 667: $hash{$columns->[$i]->{'name'}}=0;
1.13 www 668: }
669: }
1.6 matthew 670: }
671: return %hash;
672: }
1.5 matthew 673:
674: ######################################################################
675: ######################################################################
676:
677: =pod
678:
1.8 matthew 679: =item nohist_resevaldata.db data structure
680:
681: The nohist_resevaldata.db file has the following possible keys:
682:
683: Statistics Data (values are integers, perl times, or real numbers)
684: ------------------------------------------
685: $course___$resource___avetries
686: $course___$resource___count
687: $course___$resource___difficulty
688: $course___$resource___stdno
689: $course___$resource___timestamp
690:
691: Evaluation Data (values are on a 1 to 5 scale)
692: ------------------------------------------
693: $username@$dom___$resource___clear
694: $username@$dom___$resource___comments
695: $username@$dom___$resource___depth
696: $username@$dom___$resource___technical
697: $username@$dom___$resource___helpful
1.11 www 698: $username@$dom___$resource___correct
1.8 matthew 699:
700: Course Context Data
701: ------------------------------------------
702: $course___$resource___course course id
703: $course___$resource___comefrom resource preceeding this resource
704: $course___$resource___goto resource following this resource
705: $course___$resource___usage resource containing this resource
706:
707: New statistical data storage
708: ------------------------------------------
709: $course&$sec&$numstud___$resource___stats
710: $sec is a string describing the sections: all, 1 2, 1 2 3,...
711: Value is a '&' deliminated list of key=value pairs.
712: Possible keys are (currently) disc,course,sections,difficulty,
713: stdno, timestamp
714:
715: =cut
716:
717: ######################################################################
718: ######################################################################
719:
720: =pod
721:
1.5 matthew 722: =item &process_reseval_data
723:
724: Process a nohist_resevaldata hash into a more complex data structure.
725:
726: Input: Hash reference containing reseval data
727:
728: Returns: Hash with the following structure:
729:
730: $hash{$url}->{'statistics'}->{$courseid}->{'avetries'} = $value
731: $hash{$url}->{'statistics'}->{$courseid}->{'count'} = $value
732: $hash{$url}->{'statistics'}->{$courseid}->{'difficulty'} = $value
733: $hash{$url}->{'statistics'}->{$courseid}->{'stdno'} = $value
734: $hash{$url}->{'statistics'}->{$courseid}->{'timestamp'} = $value
735:
736: $hash{$url}->{'evaluation'}->{$username}->{'clear'} = $value
737: $hash{$url}->{'evaluation'}->{$username}->{'comments'} = $value
738: $hash{$url}->{'evaluation'}->{$username}->{'depth'} = $value
739: $hash{$url}->{'evaluation'}->{$username}->{'technical'} = $value
740: $hash{$url}->{'evaluation'}->{$username}->{'helpful'} = $value
741:
742: $hash{$url}->{'course'} = \@Courses
743: $hash{$url}->{'comefrom'} = \@Resources
744: $hash{$url}->{'goto'} = \@Resources
745: $hash{$url}->{'usage'} = \@Resources
746:
747: $hash{$url}->{'stats'}->{$courseid\_$section}->{$key} = $value
748:
749: =cut
750:
751: ######################################################################
752: ######################################################################
753: sub process_reseval_data {
754: my ($evaldata) = @_;
755: my %DynamicData;
756: #
757: # Process every stored element
758: while (my ($storedkey,$value) = each(%{$evaldata})) {
759: my ($source,$file,$type) = split('___',$storedkey);
760: $source = &unescape($source);
761: $file = &unescape($file);
762: $value = &unescape($value);
763: " got ".$file."\n ".$type." ".$source."\n";
764: if ($type =~ /^(avetries|count|difficulty|stdno|timestamp)$/) {
765: #
766: # Statistics: $source is course id
767: $DynamicData{$file}->{'statistics'}->{$source}->{$type}=$value;
1.11 www 768: } elsif ($type =~ /^(clear|comments|depth|technical|helpful|correct)$/){
1.5 matthew 769: #
770: # Evaluation $source is username, check if they evaluated it
771: # more than once. If so, pad the entry with a space.
772: while(exists($DynamicData{$file}->{'evaluation'}->{$type}->{$source})) {
773: $source .= ' ';
774: }
775: $DynamicData{$file}->{'evaluation'}->{$type}->{$source}=$value;
776: } elsif ($type =~ /^(course|comefrom|goto|usage)$/) {
777: #
778: # Context $source is course id or resource
779: push(@{$DynamicData{$file}->{$type}},&unescape($source));
780: } elsif ($type eq 'stats') {
781: #
782: # Statistics storage...
783: # $source is $cid\_$sec\_$stdno
784: # $value is stat1=value&stat2=value&stat3=value,....
785: #
1.8 matthew 786: my ($cid,$sec,$stdno)=split('&',$source);
787: my $crssec = $cid.'&'.$sec;
1.5 matthew 788: my @Data = split('&',$value);
789: my %Statistics;
790: while (my ($key,$value) = split('=',pop(@Data))) {
791: $Statistics{$key} = $value;
792: }
1.8 matthew 793: $sec =~ s:("$|^")::g;
794: $Statistics{'sections'} = $sec;
1.5 matthew 795: #
796: # Only store the data if the number of students is greater
797: # than the data already stored
798: if (! exists($DynamicData{$file}->{'stats'}->{$crssec}) ||
799: $DynamicData{$file}->{'stats'}->{$crssec}->{'stdno'}<$stdno){
800: $DynamicData{$file}->{'stats'}->{$crssec}=\%Statistics;
801: }
802: }
803: }
804: return %DynamicData;
805: }
806:
807:
808: ######################################################################
809: ######################################################################
810:
811: =pod
812:
813: =item &process_dynamic_metadata
814:
815: Inputs: $url: the url of the item to process
816: $DynamicData: hash reference for the results of &process_reseval_data
817:
818: Returns: Hash containing the following keys:
819: avetries, avetries_list, difficulty, difficulty_list, stdno, stdno_list,
820: course, course_list, goto, goto_list, comefrom, comefrom_list,
821: usage, clear, technical, correct, helpful, depth, comments
822:
823: Each of the return keys is associated with either a number or a string
824: The *_list items are comma-seperated strings. 'comments' is a string
825: containing generically marked-up comments.
826:
827: =cut
828:
829: ######################################################################
830: ######################################################################
831: sub process_dynamic_metadata {
832: my ($url,$DynamicData) = @_;
833: my %data;
834: my $resdata = $DynamicData->{$url};
835: #
1.8 matthew 836: # Get the statistical data - Use a weighted average
837: foreach my $type (qw/avetries difficulty disc/) {
838: my $studentcount;
1.21 albertel 839: my %course_counted;
1.5 matthew 840: my $sum;
841: my @Values;
1.8 matthew 842: my @Students;
1.5 matthew 843: #
1.21 albertel 844: # New data
1.8 matthew 845: if (exists($resdata->{'stats'})) {
846: foreach my $identifier (sort(keys(%{$resdata->{'stats'}}))) {
847: my $coursedata = $resdata->{'stats'}->{$identifier};
1.21 albertel 848: next if (lc($coursedata->{$type}) eq 'nan');
849: $course_counted{$coursedata->{'course'}}++;
1.8 matthew 850: $studentcount += $coursedata->{'stdno'};
851: $sum += $coursedata->{$type}*$coursedata->{'stdno'};
852: push(@Values,$coursedata->{$type});
853: push(@Students,$coursedata->{'stdno'});
854: }
855: }
856: #
1.21 albertel 857: # Old data
858: foreach my $course (keys(%{$resdata->{'statistics'}})) {
859: next if (exists($course_counted{$course}));
860: my $coursedata = $resdata->{'statistics'}{$course};
861: if (ref($coursedata) eq 'HASH' && exists($coursedata->{$type})) {
862: next if (lc($coursedata->{$type}) eq 'nan');
863: $studentcount += $coursedata->{'stdno'};
864: $sum += ($coursedata->{$type}*$coursedata->{'stdno'});
865: push(@Values,$coursedata->{$type});
866: push(@Students,$coursedata->{'stdno'});
867: }
868: }
1.8 matthew 869: if (defined($studentcount) && $studentcount>0) {
870: $data{$type} = $sum/$studentcount;
1.5 matthew 871: $data{$type.'_list'} = join(',',@Values);
872: }
873: }
874: #
1.8 matthew 875: # Find out the number of students who have completed the resource...
876: my $stdno;
1.20 albertel 877: my %course_counted;
1.8 matthew 878: if (exists($resdata->{'stats'})) {
879: #
880: # For the number of students, take the maximum found for the class
881: my $current_course;
882: my $coursemax=0;
883: foreach my $identifier (sort(keys(%{$resdata->{'stats'}}))) {
884: my $coursedata = $resdata->{'stats'}->{$identifier};
885: if (! defined($current_course)) {
886: $current_course = $coursedata->{'course'};
887: }
888: if ($current_course ne $coursedata->{'course'}) {
889: $stdno += $coursemax;
1.20 albertel 890: $course_counted{$coursedata->{'course'}}++;
1.8 matthew 891: $coursemax = 0;
892: $current_course = $coursedata->{'course'};
893: }
894: if ($coursemax < $coursedata->{'stdno'}) {
895: $coursemax = $coursedata->{'stdno'};
896: }
897: }
898: $stdno += $coursemax; # pick up the final course in the list
899: }
1.20 albertel 900: # check for old data that has not been run since the format was changed
901: foreach my $course (keys(%{$resdata->{'statistics'}})) {
902: next if (exists($course_counted{$course}));
903: my $coursedata = $resdata->{'statistics'}{$course};
904: if (ref($coursedata) eq 'HASH' && exists($coursedata->{'stdno'})) {
905: $stdno += $coursedata->{'stdno'};
906: }
907: }
1.8 matthew 908: $data{'stdno'}=$stdno;
909: #
1.5 matthew 910: # Get the context data
911: foreach my $type (qw/course goto comefrom/) {
912: if (defined($resdata->{$type}) &&
913: ref($resdata->{$type}) eq 'ARRAY') {
914: $data{$type} = scalar(@{$resdata->{$type}});
915: $data{$type.'_list'} = join(',',@{$resdata->{$type}});
916: }
917: }
918: if (defined($resdata->{'usage'}) &&
919: ref($resdata->{'usage'}) eq 'ARRAY') {
920: $data{'sequsage'} = scalar(@{$resdata->{'usage'}});
921: $data{'sequsage_list'} = join(',',@{$resdata->{'usage'}});
922: }
923: #
924: # Get the evaluation data
925: foreach my $type (qw/clear technical correct helpful depth/) {
926: my $count;
927: my $sum;
928: foreach my $evaluator (keys(%{$resdata->{'evaluation'}->{$type}})){
929: $sum += $resdata->{'evaluation'}->{$type}->{$evaluator};
930: $count++;
931: }
932: if ($count > 0) {
933: $data{$type}=$sum/$count;
934: }
935: }
936: #
937: # put together comments
1.26 ! bisitz 938: my $comments = '';
1.5 matthew 939: foreach my $evaluator (keys(%{$resdata->{'evaluation'}->{'comments'}})){
1.7 matthew 940: $comments .=
941: '<p>'.
1.26 ! bisitz 942: '<b>'.$evaluator.'</b>: '.
1.7 matthew 943: $resdata->{'evaluation'}->{'comments'}->{$evaluator}.
944: '</p>';
1.5 matthew 945: }
1.26 ! bisitz 946: if ($comments) {
! 947: $comments = '<div class="LCevalcomments">'
! 948: .$comments
! 949: .'</div>';
! 950: }
1.7 matthew 951: $data{'comments'} = $comments;
1.5 matthew 952: #
1.8 matthew 953: if (exists($resdata->{'stats'})) {
954: $data{'stats'} = $resdata->{'stats'};
955: }
1.12 matthew 956: if (exists($DynamicData->{'domain'})) {
957: $data{'domain'} = $DynamicData->{'domain'};
958: }
1.8 matthew 959: #
1.5 matthew 960: return %data;
961: }
962:
1.8 matthew 963: sub dynamic_metadata_storage {
964: my ($data) = @_;
965: my %Store;
966: my $courseid = $data->{'course'};
967: my $sections = $data->{'sections'};
968: my $numstu = $data->{'num_students'};
969: my $urlres = $data->{'urlres'};
970: my $key = $courseid.'&'.$sections.'&'.$numstu.'___'.$urlres.'___stats';
971: $Store{$key} =
972: 'course='.$courseid.'&'.
973: 'sections='.$sections.'&'.
974: 'timestamp='.time.'&'.
975: 'stdno='.$data->{'num_students'}.'&'.
976: 'avetries='.$data->{'mean_tries'}.'&'.
977: 'difficulty='.$data->{'deg_of_diff'};
978: if (exists($data->{'deg_of_disc'})) {
979: $Store{$key} .= '&'.'disc='.$data->{'deg_of_disc'};
980: }
981: return %Store;
982: }
1.6 matthew 983:
1.16 raeburn 984: ###############################################################
985: ###############################################################
986: ### ###
987: ### &portfolio_metadata($filepath,$dom,$uname,$group) ###
988: ### Retrieve metadata for the given file ###
989: ### Returns array - ###
990: ### contains reference to metadatahash and ###
991: ### optional reference to addedfields hash ###
992: ### ###
993: ###############################################################
994: ###############################################################
995:
996: sub portfolio_metadata {
997: my ($fullpath,$dom,$uname,$group)=@_;
998: my ($mime) = ( $fullpath=~/\.(\w+)$/ );
999: my %metacache=();
1000: if ($fullpath !~ /\.meta$/) {
1001: $fullpath .= '.meta';
1002: }
1003: my (@standard_fields,%addedfields);
1004: my $colsref = $Portfolio_metadata_table_description;
1005: if (ref($colsref) eq 'ARRAY') {
1006: my @columns = @{$colsref};
1007: foreach my $coldata (@columns) {
1008: push(@standard_fields,$coldata->{'name'});
1009: }
1010: }
1011: my $metastring=&getfile($fullpath);
1012: if (! defined($metastring)) {
1013: $metacache{'keys'}= 'owner,domain,mime';
1014: $metacache{'owner'} = $uname.':'.$dom;
1015: $metacache{'domain'} = $dom;
1016: $metacache{'mime'} = $mime;
1017: if ($group ne '') {
1018: $metacache{'keys'} .= ',courserestricted';
1019: $metacache{'courserestricted'} = 'course.'.$dom.'_'.$uname;
1020: }
1021: } else {
1022: my $parser=HTML::TokeParser->new(\$metastring);
1023: my $token;
1024: while ($token=$parser->get_token) {
1025: if ($token->[0] eq 'S') {
1026: my $entry=$token->[1];
1027: if ($metacache{'keys'}) {
1028: $metacache{'keys'}.=','.$entry;
1029: } else {
1030: $metacache{'keys'}=$entry;
1031: }
1032: my $value = $parser->get_text('/'.$entry);
1033: if (!grep(/^\Q$entry\E$/,@standard_fields)) {
1034: my $clean_value = lc($value);
1035: $clean_value =~ s/\s/_/g;
1036: if ($clean_value ne $entry) {
1037: if (defined($addedfields{$entry})) {
1038: $addedfields{$entry} .=','.$value;
1039: } else {
1040: $addedfields{$entry} = $value;
1041: }
1042: }
1043: } else {
1044: $metacache{$entry} = $value;
1045: }
1046: }
1047: } # End of ($token->[0] eq 'S')
1.22 albertel 1048:
1049: if (!exists($metacache{'domain'})) {
1050: $metacache{'domain'} = $dom;
1051: }
1.16 raeburn 1052: }
1053: return (\%metacache,$metacache{'courserestricted'},\%addedfields);
1054: }
1055:
1056: sub process_portfolio_access_data {
1057: my ($dbh,$simulate,$newnames,$url,$fullpath,$access_hash,$caller) = @_;
1058: my %loghash;
1059: if ($caller eq 'update') {
1060: # Delete old data (no error if deleting non-existent record).
1.23 raeburn 1061: my $error;
1062: if ($url eq '') {
1063: $error = 'No url specified';
1064: } else {
1065: my $delitem = 'url = '.$dbh->quote($url);
1066: $error=&delete_metadata($dbh,$newnames->{'access'},$delitem);
1067: }
1.16 raeburn 1068: if (defined($error)) {
1069: $loghash{'access'}{'err'} = "MySQL Error Delete: ".$error;
1070: return %loghash;
1071: }
1072: }
1073: # Check the file exists
1074: if (-e $fullpath) {
1075: foreach my $key (keys(%{$access_hash})) {
1076: my $acc_data;
1077: $acc_data->{url} = $url;
1078: $acc_data->{keynum} = $key;
1079: my ($num,$scope,$end,$start) =
1080: ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1081: next if (($scope ne 'public') && ($scope ne 'guest'));
1082: $acc_data->{scope} = $scope;
1083: if ($end != 0) {
1084: $acc_data->{end} = &sqltime($end);
1085: }
1086: $acc_data->{start} = &sqltime($start);
1087: if (! $simulate) {
1088: my ($count,$err) =
1089: &store_metadata($dbh,$newnames->{'access'},
1090: 'portfolio_access',$acc_data);
1091: if ($err) {
1092: $loghash{$key}{'err'} = "MySQL Error Insert: ".$err;
1093: }
1094: if ($count < 1) {
1095: $loghash{$key}{'count'} =
1096: "Unable to insert record into MySQL database for $url";
1097: }
1098: }
1099: }
1100: }
1101: return %loghash;
1102: }
1103:
1104: sub process_portfolio_metadata {
1105: my ($dbh,$simulate,$newnames,$url,$fullpath,$is_course,$dom,$uname,$group,$caller) = @_;
1106: my %loghash;
1107: if ($caller eq 'update') {
1108: # Delete old data (no error if deleting non-existent record).
1.23 raeburn 1109: my ($error,$delitem);
1110: if ($url eq '') {
1111: $error = 'No url specified';
1112: } else {
1113: $delitem = 'url = '.$dbh->quote($url);
1114: $error=&delete_metadata($dbh,$newnames->{'portfolio'},$delitem);
1115: }
1.16 raeburn 1116: if (defined($error)) {
1117: $loghash{'metadata'}{'err'} = "MySQL Error delete metadata: ".
1118: $error;
1119: return %loghash;
1120: }
1.23 raeburn 1121: $error=&delete_metadata($dbh,$newnames->{'addedfields'},$delitem);
1.16 raeburn 1122: if (defined($error)) {
1123: $loghash{'addedfields'}{'err'}="MySQL Error delete addedfields: ".$error;
1124: }
1125: }
1126: # Check the file exists.
1127: if (-e $fullpath) {
1128: my ($ref,$crs,$addedfields) = &portfolio_metadata($fullpath,$dom,$uname,
1129: $group);
1130: &getfiledates($ref,$fullpath);
1131: if ($is_course) {
1132: $ref->{'groupname'} = $group;
1133: }
1134: my %Data;
1135: if (ref($ref) eq 'HASH') {
1136: %Data = %{$ref};
1137: }
1138: %Data = (
1139: %Data,
1140: 'url'=>$url,
1141: 'version'=>'current',
1142: );
1143: my %loghash;
1144: if (! $simulate) {
1145: my ($count,$err) =
1146: &store_metadata($dbh,$newnames->{'portfolio'},'portfolio_metadata',
1147: \%Data);
1148: if ($err) {
1149: $loghash{'metadata'."\0"}{'err'} = "MySQL Error Insert: ".$err;
1150: }
1151: if ($count < 1) {
1152: $loghash{'metadata'."\0"}{'count'} = "Unable to insert record into MySQL portfolio_metadata database table for $url";
1153: }
1154: if (ref($addedfields) eq 'HASH') {
1155: if (keys(%{$addedfields}) > 0) {
1156: foreach my $key (keys(%{$addedfields})) {
1157: my $added_data = {
1158: 'url' => $url,
1159: 'field' => $key,
1160: 'value' => $addedfields->{$key},
1161: 'courserestricted' => $crs,
1162: };
1163: my ($count,$err) =
1164: &store_metadata($dbh,$newnames->{'addedfields'},
1165: 'portfolio_addedfields',$added_data);
1166: if ($err) {
1167: $loghash{$key}{'err'} =
1168: "MySQL Error Insert: ".$err;
1169: }
1170: if ($count < 1) {
1171: $loghash{$key}{'count'} = "Unable to insert record into MySQL portfolio_addedfields database table for url = $url and field = $key";
1172: }
1173: }
1174: }
1175: }
1176: }
1177: }
1178: return %loghash;
1179: }
1180:
1.23 raeburn 1181: sub process_allusers_data {
1182: my ($dbh,$simulate,$newnames,$uname,$udom,$userdata,$caller) = @_;
1183: my %loghash;
1184: if ($caller eq 'update') {
1185: # Delete old data (no error if deleting non-existent record).
1186: my ($error,$delitem);
1187: if ($udom eq '' || $uname eq '' ) {
1188: $error = 'No domain and/or username specified';
1189: } else {
1.25 raeburn 1190: $delitem = 'domain = '.$dbh->quote($udom).' AND username '.
1191: 'COLLATE latin1_general_cs = '.$dbh->quote($uname);
1.23 raeburn 1192: $error=&delete_metadata($dbh,$newnames->{'allusers'},$delitem);
1193: }
1194: if (defined($error)) {
1195: $loghash{'err'} = 'MySQL Error in allusers delete: '.$error;
1196: return %loghash;
1197: }
1198: }
1199: if (!$simulate) {
1200: if ($udom ne '' && $uname ne '') {
1201: my ($count,$err) = &store_metadata($dbh,$newnames->{'allusers'},
1202: 'allusers',$userdata);
1203: if ($err) {
1204: $loghash{'err'} = 'MySQL Error in allusers insert: '.$err;
1205: }
1206: if ($count < 1) {
1207: $loghash{'count'} =
1208: 'Unable to insert record into MySQL allusers database for '.
1209: $uname.' in '.$udom;
1210: }
1211: } else {
1212: $loghash{'err'} =
1213: 'MySQL Error allusrs insert: missing username and/or domain';
1214: }
1215: }
1216: return %loghash;
1217: }
1218:
1.5 matthew 1219: ######################################################################
1220: ######################################################################
1.14 raeburn 1221:
1.16 raeburn 1222: sub getfile {
1223: my $file = shift();
1224: if (! -e $file ) {
1225: return undef;
1226: }
1.17 albertel 1227: open(my $fh,"<$file");
1.16 raeburn 1228: my $contents = '';
1229: while (<$fh>) {
1230: $contents .= $_;
1231: }
1232: return $contents;
1233: }
1234:
1235: ##
1236: ## &getfiledates()
1237: ## Converts creationdate and modifieddates to SQL format
1238: ## Applies stat() to file to retrieve dates if missing
1239: sub getfiledates {
1240: my ($ref,$target) = @_;
1241: if (! defined($ref->{'creationdate'}) ||
1242: $ref->{'creationdate'} =~ /^\s*$/) {
1243: $ref->{'creationdate'} = (stat($target))[9];
1244: }
1245: if (! defined($ref->{'lastrevisiondate'}) ||
1246: $ref->{'lastrevisiondate'} =~ /^\s*$/) {
1247: $ref->{'lastrevisiondate'} = (stat($target))[9];
1248: }
1249: $ref->{'creationdate'} = &sqltime($ref->{'creationdate'});
1250: $ref->{'lastrevisiondate'} = &sqltime($ref->{'lastrevisiondate'});
1251: }
1252:
1.15 raeburn 1253: ##
1254: ## &sqltime($timestamp)
1255: ##
1256: ## Convert perl $timestamp to MySQL time. MySQL expects YYYY-MM-DD HH:MM:SS
1257: ##
1258: sub sqltime {
1259: my ($time) = @_;
1260: my $mysqltime;
1261: if ($time =~
1262: /(\d+)-(\d+)-(\d+) # YYYY-MM-DD
1263: \s # a space
1264: (\d+):(\d+):(\d+) # HH:MM::SS
1265: /x ) {
1266: # Some of the .meta files have the time in mysql
1267: # format already, so just make sure they are 0 padded and
1268: # pass them back.
1269: $mysqltime = sprintf('%04d-%02d-%02d %02d:%02d:%02d',
1270: $1,$2,$3,$4,$5,$6);
1271: } elsif ($time =~ /^\d+$/) {
1272: my @TimeData = gmtime($time);
1273: # Alter the month to be 1-12 instead of 0-11
1274: $TimeData[4]++;
1275: # Alter the year to be from 0 instead of from 1900
1276: $TimeData[5]+=1900;
1277: $mysqltime = sprintf('%04d-%02d-%02d %02d:%02d:%02d',
1278: @TimeData[5,4,3,2,1,0]);
1279: } elsif (! defined($time) || $time == 0) {
1280: $mysqltime = 0;
1281: } else {
1282: &log(0," sqltime:Unable to decode time ".$time);
1283: $mysqltime = 0;
1284: }
1285: return $mysqltime;
1286: }
1.14 raeburn 1287:
1288: ######################################################################
1289: ######################################################################
1.5 matthew 1290: ##
1291: ## The usual suspects, repeated here to reduce dependency hell
1292: ##
1293: ######################################################################
1294: ######################################################################
1295: sub unescape {
1296: my $str=shift;
1297: $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1298: return $str;
1299: }
1300:
1301: sub escape {
1302: my $str=shift;
1303: $str =~ s/(\W)/"%".unpack('H2',$1)/eg;
1304: return $str;
1305: }
1.6 matthew 1306:
1.1 matthew 1307: 1;
1308:
1309: __END__;
1310:
1311: =pod
1312:
1313: =back
1314:
1315: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>