Repository navigation
Expand file tree
/
Copy pathparseLibrary_v0.php
More file actions
1534 lines (1313 loc) · 48.5 KB
/
Copy pathparseLibrary_v0.php
File metadata and controls
1534 lines (1313 loc) · 48.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include_once ("result.php");
include_once ("conflict.php");
/**
* @file
* \author Bo Brinkman
* \author Eliot Fowler
* \copyright All rights reserved
* \brief Parses the LC Call Number passed to 10 fields and then outputs it as
* an associative array.
*
* \b Error \b Causes:
* \arg Alphabetic portion doesn't exist
* \arg Alphabetic portion longer than three characters
* \arg Whole class portion doesn't exist
* \arg Whole class portion longer than four numbers
* \arg Space before the whole class portion
* \arg Decimal portion longer than four numbers
* \arg Space before the decimal portion
* \arg First Date field indicates ebook
* \arg First Date field contains other alphabetic characters
* \arg First Cutter doesn't exist
* \arg First Cutter has more than five numbers
* \arg First Cutter doesn't contain any numerical portion
* \arg First Cutter has trailing letters
* \arg First Cutter indicates ebook
* \arg First Cutter doesn't contain the alphabetic portion
* \arg Second Date field indicates ebook
* \arg Second Date field contains other alphabetic characters
* \arg Second Cutter has more than five numbers
* \arg Second Cutter has trailing letters
* \arg Second Cutter indicates ebook
* \arg All fields empty
* \arg All fields full
* \arg Extra characters found (other than ".", " ")
* \arg Ends with something other than a number or letter (such as a period)
* \arg Trailing and leading whitespace
*
* \b Warning \b Causes:
* \arg The fields element 8, element 9, and element 10 are not empty (currently ShelvAR does not support those fields)
* \arg First Cutter doesnt't contain a period
*
*
* \b Output:
* An associative array with the following 10 fields:
* \arg alphabetic
* \arg wholeClass
* \arg decClass
* \arg date1
* \arg cutter1
* \arg date2
* \arg cutter2
* \arg element8
* \arg element9
* \arg element10
*
*
* @see http://www.oclc.org/bibformats/en/0xx/050.shtm
*
* @version March 18, 2012
* \note Used by librariantagger.js, book_sleuth, book_seen
*/
/**
* Array of size variables
**/
$GLOBALS['arrOfSizes']=null;
/**
* Variable that keeps track of spaces before each field (except the first)
**/
$GLOBALS['arrOfSpaces']=null;
/**
* Result object
**/
$GLOBALS['res']=null;
function initialize()
{
global $arrOfConflicts, $arrOfSizes, $arrOfSpaces, $res;
$arrOfConflicts = array();
$res = new result();
$res->endResult["allow"] = true;
$res->endResult["warningFree"] = true;
$arrOfSizes = array('alphabeticSize' => 0, 'wholeClassSize' => 0, 'decClassSize' => 0, 'date1Size' => 0, 'cutter1Size' => 0, 'date2Size' => 0,
'cutter2Size' => 0, 'element8Size' => 0, '$element9Size' => 0, 'element10Size' => 0);
$arrOfSpaces = array('spacesBeforeWhole' => 0, 'spacesBeforeDec' => 0, 'spacesBeforeDate1' => 0, 'spacesBeforeCut1' => 0, 'spacesBeforeDate2' => 0, 'spacesBeforeCut2' => 0,
'spacesBeforeEle8' => 0, 'spacesBeforeEle9' => 0, 'spacesBeforeEle10' => 0);
}
/**
* Takes a string as input and attempts to parse the call number
*
* Multiple methods are called
* in order to parse a string into the 10 fields of a call number.
* The way the string is parsed is by keeping track of how many characters
* were in each of the previous sections, how many spaces there have been, and
* by using the guidelines previously described.
*
* @param lcNum
* The input string,
*
* @return
* An associative array that contains the information held in the parsedArr variable.
*
**/
function parseToAssocArray_delegate($lcNum)
{
global $arrOfConflicts, $res, $parsedArr;
initialize();
$lcnumi = $lcNum;
$lcNum = trim_excess_whitespace($lcnumi);
if(strcmp($lcnumi, $lcNum) != 0) {
//We trimmed, should add warning.
addConflictTrimmedWhitspace();
}
$parsedArr["alphabetic"] = strtoupper(getAlphabetic($lcNum));
$parsedArr["wholeClass"] = getWholeClass($lcNum);
$parsedArr["decClass"] = getDecClass($lcNum);
$parsedArr["date1"] = strtoupper(getDate1($lcNum));
$parsedArr["cutter1"] = strtoupper(getCutter1($lcNum));
$parsedArr["date2"] = strtoupper(getDate2($lcNum));
$parsedArr["cutter2"] = strtoupper(getCutter2($lcNum));
$parsedArr["element8"] = strtoupper(getElement8($lcNum));
$parsedArr["element8meaning"] = getElement8Meaning($parsedArr["element8"]);
$parsedArr["element9"] = strtoupper(getElement9($lcNum));
$parsedArr["element10"] = strtoupper(getElement10($lcNum));
fixDateFields();
checkForBugs($lcNum);
$res->endResult["lcNum"] = $parsedArr;
$res->endResult["parserVersion"] = 0;
$res->endResult["originalInput"] = $lcNum;
$res->endResult["arrOfConflicts"] = $arrOfConflicts;
return $res->endResult;
}
/**
* Parses the alphabetic portion of the LC number
**/
function getAlphabetic($lcNum)
{
global $arrOfSizes;
$chars = 0;
$loc = 0;
$cur = substr($lcNum, 0, 1);
while(ctype_alpha($cur) && $loc < strlen($lcNum))
{
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$arrOfSizes['alphabeticSize'] = $chars;
$result = substr($lcNum, 0, $chars);
if($chars > 3)
{
addConflictAlphaTooBig();
}
else if($chars == 0)
{
addConflictAlphaExistence();
}
return $result;
}
/**
* Parses the whole number part of the class portion of the call number
**/
function getWholeClass($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars=0;
$loc = $arrOfSizes['alphabeticSize'] + $arrOfSpaces['spacesBeforeWhole'];
$cur = substr($lcNum, $loc, 1);
$spaceBeforeWhole = false;
if($cur == " ")
{
$spaceBeforeWhole = true;
$arrOfSpaces['spacesBeforeWhole']++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$numSize = 0;
while(is_numeric($cur) && $loc < strlen($lcNum))
{
$numSize++;
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$arrOfSizes['wholeClassSize'] = $chars;
if($spaceBeforeWhole)
addConflictSpaceBeforeWhole();
if($numSize > 4)
{
addConflictWholeNumbersTooMany();
}
$result = substr($lcNum, $arrOfSizes['alphabeticSize'] + $arrOfSpaces['spacesBeforeWhole'], $chars);
if($chars == 0)
{
addConflictWholeExistence();
return "";
}
return $result;
}
/**
* Parses the decimal number part of the class portion of the call number
**/
function getDecClass($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars=0;
$origLoc = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize'] + $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'];
$loc = $origLoc;
$cur = substr($lcNum, $loc, 1);
//Either not dec class or not correct
//
//We should never leave the if statement and stay in the function
//without at least returning an error.
if($cur == " " && substr($lcNum, $loc+1, 1) == ".")
{
$arrOfSpaces['spacesBeforeDec']++;
//if we are truely in the decimal portion and not the cutter
if(is_numeric(substr($lcNum, $loc+2, 1)))
{
$loc++;
$cur = substr($lcNum, $loc, 1);
}
//if we are in the cutter portion
else if(ctype_alpha(substr($lcNum, $loc+2, 1)))
{
return "";
}
}
if($cur == ".")
{
$chars++;
$loc++;
$numSize = 0;
if(!is_numeric(substr($lcNum, $loc, 1)))
{
//should probably send an error here
return "";
}
while(is_numeric(substr($lcNum, $loc, 1)) && $loc < strlen($lcNum))
{
$numSize++;
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$arrOfSizes['decClassSize'] = $chars;
if($arrOfSpaces['spacesBeforeDec'] > 0)
addConflictSpaceBeforeDecimal();
if($numSize > 3)
{
addConflictDecNumsTooMany();
}
$result = substr($lcNum, $origLoc + $arrOfSpaces['spacesBeforeDec'] + 1, $arrOfSizes['decClassSize'] - 1); //+ and - 1 are for the decimal
return $result;
}
return "";
}
/**
* Parses the first date of the call number
**/
function getDate1($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars=0;
$date1numeric = 0;
$origLoc = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'];
$loc = $origLoc;
$cur = substr($lcNum, $loc, 1);
if($cur == " " && is_numeric(substr($lcNum, $loc+1, 1)))
{
$loc++;
$cur = substr($lcNum, $loc, 1);
$arrOfSpaces['spacesBeforeDate1']++;
while(is_numeric($cur))
{
$date1numeric++;
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
if($chars > 0)
{
while(ctype_alpha($cur))
{
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
}
}
if($chars > 1)
$arrOfSizes['date1Size']= $chars;
else {
$arrOfSizes['date1Size']= 0;
return "";
}
$result = substr($lcNum, $origLoc + $arrOfSpaces['spacesBeforeDate1'], $arrOfSizes['date1Size']);
/*
//check ebook
if(strtolower(substr($result, $date1numeric)) == "eb")
addConflictIsEbook1();
else if($arrOfSizes['date1Size'] > $date1numeric)
addConflictDate1HasAlpha();
if(intval($result) > 4095)
addConflictDate1TooLong();
*/
return $result;
}
/**
* Parses the first cutter number of the call number
**/
function getCutter1($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars = 0;
$origLoc = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size'] + $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'] + $arrOfSpaces['spacesBeforeDate1'];
$loc = $origLoc;
$cur = substr($lcNum, $loc, 1);
$cutter1MissingPeriod = false;
if($cur == " ")
{
$arrOfSpaces['spacesBeforeCut1']++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
if($cur == "." || ctype_alpha($cur))
{
if($cur == '.'){
//accounting for the decimal
$arrOfSpaces['spacesBeforeCut1']++;
$loc++;
} else {
$cutter1MissingPeriod = true;
}
if(ctype_alpha(substr($lcNum, $loc, 1)))
{
$chars++; //accounting for the initial letter
$loc++;
$cur = substr($lcNum, $loc, 1);
$numCount = 0;
while(is_numeric($cur) && $loc < strlen($lcNum))
{
$numCount++;
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
while((ctype_alpha($cur) || is_numeric($cur)) && $loc < strlen($lcNum)){
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$arrOfSizes['cutter1Size']= $chars;
if($numCount > 5)
{
addConflictTooManyCutter1NumsError();
}
if($numCount == 0)
addConflictNoNumsInCutter1Num();
if($cutter1MissingPeriod)
addConflictCutter1MissingPeriod();
$result = substr($lcNum, $origLoc + $arrOfSpaces['spacesBeforeCut1'], $chars);
if($numCount != $chars-1){
if(strtolower(substr($result,-2)) == 'eb'){
addConflictCutter1IndicatesEbook();
} else if(strtolower(substr($result,-1)) != 'x') {
addConflictCutter1HasTrailingLetters();
}
}
if($chars == 0)
return "";
return $result;
}
else {
addConflictCutter1MissingLetter();
}
}
return "";
}
/**
* Parses the second date of the call number
**/
function getDate2($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars=0;
$origLoc = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSizes['cutter1Size']+ $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'] + $arrOfSpaces['spacesBeforeDate1'] + $arrOfSpaces['spacesBeforeCut1'];
$loc = $origLoc;
$cur = substr($lcNum, $loc, 1);
$date2numeric = 0;
if($cur == " " && is_numeric(substr($lcNum, $loc+1, 1)))
{
$loc++;
$cur = substr($lcNum, $loc, 1);
$arrOfSpaces['spacesBeforeDate2']++;
while(is_numeric($cur))
{
$date2numeric++;
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
if($chars > 0)
{
while(ctype_alpha($cur))
{
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
}
}
if($chars > 1)
$arrOfSizes['date2Size']= $chars;
else {
$arrOfSizes['date2Size']= 0;
return "";
}
$result = substr($lcNum, $origLoc + $arrOfSpaces['spacesBeforeDate2'], $arrOfSizes['date2Size']);
/*
//check ebook
if(strtolower(substr($result, -2)) == "eb")
addConflictIsEbook2();
if($date2numeric < $arrOfSizes['date2Size']){
addConflictDate2HasAlpha();
}
if(intval($result) > 4095)
addConflictDate2TooLong();
*/
return $result;
}
/**
* Parses the second cutter number of the call number
**/
function getCutter2($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars=0;
$origLoc = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSizes['cutter1Size'] + $arrOfSizes['date2Size'] + $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'] + $arrOfSpaces['spacesBeforeDate1'] + $arrOfSpaces['spacesBeforeCut1'] + $arrOfSpaces['spacesBeforeDate2'];
$loc = $origLoc;
$cur = substr($lcNum, $loc, 1);
if($cur == " ")
{
$arrOfSpaces['spacesBeforeCut2']++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
if($cur == ".")
{
//@AB no reason cutter 2 should have period; throw error
addConflictPeriodInCutter2Num();
// $arrOfSpaces['spacesBeforeCut2']++; //Does this fix the problem? RED FLAG RED FLAG RED FLAG! WHAT IS THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// $loc++;
// $cur = substr($lcNum, $loc, 1);
}
if(preg_match("/^[A-Z]$/i", $cur))
{
//TODO: This gives weird results if one enters a bad cutter like "pp44"
while(ctype_alpha($cur))
{
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
if($chars > 1) {
addConflictTooManyCutter2AlphasError($chars);
}
$numCount = 0;
while(is_numeric($cur) && $loc < strlen($lcNum))
{
$numCount++;
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
while((ctype_alpha($cur) || is_numeric($cur)) && $loc < strlen($lcNum)){
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$arrOfSizes['cutter2Size'] = $chars;
if($numCount > 5)
addConflictTooManyCutter2NumsError();
$result = substr($lcNum, $origLoc + $arrOfSpaces['spacesBeforeCut2'], $chars);
if($numCount != $arrOfSizes['cutter2Size'] - 1){
if(strtolower(substr($result,-2)) == 'eb'){
addConflictCutter2IndicatesEbook();
}
else if(strtolower(substr($result,-1)) != 'x') {
addConflictCutter2HasTrailingLetters($numCount);
}
}
if($numCount == 0)
addConflictNoNumsInCutter2Num();
if($chars == 0)
return "";
return $result;
}
return "";
}
/**
* Parses the 8th element of the call number
**/
function getElement8($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars=0;
$origLoc = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSizes['cutter1Size']+ $arrOfSizes['date2Size']+ $arrOfSizes['cutter2Size'] + $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'] + $arrOfSpaces['spacesBeforeDate1'] + $arrOfSpaces['spacesBeforeCut1'] + $arrOfSpaces['spacesBeforeDate2'] + $arrOfSpaces['spacesBeforeCut2'];
$loc = $origLoc;
$cur = substr($lcNum, $loc, 1);
if($cur == " ")
{
$arrOfSpaces['spacesBeforeEle8']++;
$loc++;
}
$cur = substr($lcNum, $loc, 1);
while((preg_match("/^[a-z]$/i", $cur) || is_numeric($cur)) && $loc < strlen($lcNum))
{
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$arrOfSizes['element8Size'] = $chars;
if($cur == '.')
{
$loc++;
$cur = substr($lcNum, $loc, 1);
if($cur == " ")
{
$arrOfSpaces['spacesBeforeEle8']++;
$chars++; //account for period
$arrOfSizes['element8Size'] = $chars;
}
}
$result = substr($lcNum, $origLoc + $arrOfSpaces['spacesBeforeEle8'], $chars);
if($chars == 0)
return "";
/* else if(getElement8Meaning($result) == 'year')
{
if(intval($result) > 4095)
addConflictDate3TooBig();
if(strtoupper(substr($result,4,2)) == 'EB')
addConflictDate3isEbook();
}
else addConflictElement8NotDate3(); */
return $result;
}
/**
* Parses the 8th element of the call number
**/
function getElement9($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars=0;
$origLoc = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSizes['cutter1Size']+ $arrOfSizes['date2Size']+ $arrOfSizes['cutter2Size'] + $arrOfSizes['element8Size'] + $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'] + $arrOfSpaces['spacesBeforeDate1'] + $arrOfSpaces['spacesBeforeCut1'] + $arrOfSpaces['spacesBeforeDate2'] + $arrOfSpaces['spacesBeforeCut2'] + $arrOfSpaces['spacesBeforeEle8'];
$loc = $origLoc;
$cur = substr($lcNum, $loc, 1);
if($cur == " ")
{
$arrOfSpaces['spacesBeforeEle9']++;
$loc++;
}
$cur = substr($lcNum, $loc, 1);
while((preg_match("/^[a-z]$/i", $cur) || is_numeric($cur)) && $loc < strlen($lcNum))
{
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$arrOfSizes['element9Size']= $chars;
$result = substr($lcNum, $origLoc + $arrOfSpaces['spacesBeforeEle9'], $chars);
if($chars == 0)
return "";
return $result;
}
/**
* Parses the 8th element of the call number
**/
function getElement10($lcNum)
{
global $arrOfSizes, $arrOfSpaces;
$chars=0;
$origLoc = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSizes['cutter1Size']+ $arrOfSizes['date2Size']+ $arrOfSizes['cutter2Size'] + $arrOfSizes['element8Size'] + $arrOfSizes['element9Size']+ $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'] + $arrOfSpaces['spacesBeforeDate1'] + $arrOfSpaces['spacesBeforeCut1'] + $arrOfSpaces['spacesBeforeDate2'] + $arrOfSpaces['spacesBeforeCut2'] + $arrOfSpaces['spacesBeforeEle8'] + $arrOfSpaces['spacesBeforeEle9'];
$loc = $origLoc;
$cur = substr($lcNum, $loc, 1);
if($cur == " ")
{
$arrOfSpaces['spacesBeforeEle10']++;
$loc++;
}
$cur = substr($lcNum, $loc, 1);
while($loc < strlen($lcNum))
{
$chars++;
$loc++;
$cur = substr($lcNum, $loc, 1);
}
$arrOfSizes['element10Size']= $chars;
$result = substr($lcNum, $origLoc + $arrOfSpaces['spacesBeforeEle10'], $chars);
if($chars == 0)
return "";
return $result;
}
function trim_excess_whitespace($str) {
$ro = preg_replace('/\s+/', ' ', $str);
return $str;
}
// @cond ASDF
/**
* Adds conflict if alphabetic portion doesn't exist
**/
function addConflictAlphaExistence()
{
global $arrOfConflicts, $res;
$problem = new conflict();
$problem->msg = "The alphabetic portion of the call number doesn't appear to exist";
$problem->isWarning = false;
$problem->conflictStart = 0;
$problem->conflictEnd = 0;
$arrOfConflicts[] = $problem;
$res->endResult["allow"] = false;
$res->endResult["warningFree"] = false;
}
/**
* Adds conflict if alphabetic portion too big
**/
function addConflictAlphaTooBig()
{
global $arrOfConflicts, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "The alphabetic portion of this call number seems to be longer than three letters.";
$problem->isWarning = false;
$problem->conflictStart = 0;
$problem->conflictEnd = $arrOfSizes['alphabeticSize'] - 1;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if whole portion doesn't exist
**/
function addConflictWholeExistence()
{
global $arrOfConflicts, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "The whole number portion of the call number doesn't appear to exist";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'];
$problem->conflictEnd = $problem->conflictStart;
$arrOfConflicts[] = $problem;
$res->endResult["allow"] = false;
$res->endResult["warningFree"] = false;
}
/**
* Adds conflict if space found before whole number
**/
function addConflictSpaceBeforeWhole()
{
global $arrOfConflicts, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "There appears to be a space before the whole number";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'];
$problem->conflictEnd = $problem->conflictStart;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if too many whole numbers
**/
function addConflictWholeNumbersTooMany()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "Your whole number portion of the call number is longer than the allowed four numbers";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['spacesBeforeWhole'];
$problem->conflictEnd = $problem->conflictStart + $arrOfSizes['wholeClassSize'] - 1;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if space found before decimal number
**/
function addConflictSpaceBeforeDecimal()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "There appears to be a space before the decimal number";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize'];
$problem->conflictEnd = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize'];
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if too many decimal numbers
**/
function addConflictDecNumsTooMany()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "Your decimal number portion of the call number is longer than the allowed three numbers";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSpaces['spacesBeforeWhole']+ $arrOfSpaces['spacesBeforeDec'] + 1;
$problem->conflictEnd = $problem->conflictStart + $arrOfSizes['decClassSize'] - 1;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if ebook in date1
**/
function addConflictIsEbook1()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "This appears to be an e-book, based on the \"eb\" in the first date field.";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + ($arrOfSizes['date1Size']- 2) + $arrOfSpaces['spacesBeforeWhole']
+ $arrOfSpaces['spacesBeforeDec']+ $arrOfSpaces['spacesBeforeDate1'];
$problem->conflictEnd = $problem->conflictStart + 1;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if date1 has alpha
**/
function addConflictDate1HasAlpha()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "Alphabetic characters not currently supported in date 1. Date must be a 4-digit year.";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + 4 + $arrOfSpaces['spacesBeforeWhole'] + $arrOfSpaces['spacesBeforeDec'] + $arrOfSpaces['spacesBeforeDate1'];
$problem->conflictEnd = $problem->conflictStart + ($arrOfSizes['date1Size']- 4);
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if date1 too long
**/
function addConflictDate1TooLong()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "The first date field is larger than 4095.";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSpaces['spacesBeforeWhole']+ $arrOfSpaces['spacesBeforeDec']
+ $arrOfSpaces['spacesBeforeDate1'];
$problem->conflictEnd = $problem->conflightStart + $arrOfSizes['date1Size']- 1;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if cutter1 doesn't exist
**/
function addConflictCutter1Existence()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "The first cutter number of the call number doesn't appear to exist";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSpaces['spacesBeforeWhole']
+ $arrOfSpaces['spacesBeforeDec']+ $arrOfSpaces['spacesBeforeDate1']+ $arrOfSpaces['spacesBeforeCut1'];
$problem->conflictEnd = $problem->conflictStart;
$arrOfConflicts[] = $problem;
$res->endResult["allow"] = false;
$res->endResult["warningFree"] = false;
}
/**
* Adds conflict if cutter1 missing period
**/
function addConflictCutter1MissingPeriod()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "It appears that the period that is supposed to precede the first cutter is missing. We have added it. If this is incorrect, revise your data entry.";
$problem->isWarning = true;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSpaces['spacesBeforeWhole']
+ $arrOfSpaces['spacesBeforeDec']+ $arrOfSpaces['spacesBeforeDate1']+ $arrOfSpaces['spacesBeforeCut1']- 1;
$problem->conflictEnd = $problem->conflictStart;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
}
/**
* Adds conflict if too many nums in cutter1
**/
function addConflictTooManyCutter1NumsError()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res, $problem;
$problem = new conflict();
$problem->msg = "It appears that you have 6 or more numbers in your first cutter number and the maximum allowed is 3.";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSpaces['spacesBeforeWhole']
+ $arrOfSpaces['spacesBeforeDec']+ $arrOfSpaces['spacesBeforeDate1']+ $arrOfSpaces['spacesBeforeCut1'];
$problem->conflictEnd = $problem->conflictStart + $arrOfSizes['cutter1Size']- 1;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if no nums in cutter1
**/
function addConflictNoNumsInCutter1Num()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "The first cutter number has no numerical portion";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ $arrOfSizes['cutter1Size']
+ $arrOfSpaces['spacesBeforeWhole']+ $arrOfSpaces['spacesBeforeDec']+ $arrOfSpaces['spacesBeforeDate1']+ $arrOfSpaces['spacesBeforeCut1'];
$problem->conflictEnd = $problem->conflictStart;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if trailing letters in cutter1
**/
function addConflictCutter1HasTrailingLetters()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "The only trailing letter currently supported in the first cutter is \"x\".";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + $arrOfSizes['date1Size']+ ($arrOfSizes['cutter1Size']- 1) +
$arrOfSpaces['spacesBeforeWhole']+ $arrOfSpaces['spacesBeforeDec']+ $arrOfSpaces['spacesBeforeDate1']+ $arrOfSpaces['spacesBeforeCut1'];
$problem->conflictEnd = $problem->conflictStart;
$arrOfConflicts[] = $problem;
$res->endResult["warningFree"] = false;
$res->endResult["allow"] = false;
}
/**
* Adds conflict if cutter1 indicates ebook
**/
function addConflictCutter1IndicatesEbook()
{
global $arrOfConflicts, $arrOfSpaces, $arrOfSizes, $res;
$problem = new conflict();
$problem->msg = "This appears to be an e-book, based on the \"eb\" in the first cutter field.";
$problem->isWarning = false;
$problem->conflictStart = $arrOfSizes['alphabeticSize'] + $arrOfSizes['wholeClassSize']+ $arrOfSizes['decClassSize'] + ($arrOfSizes['cutter1Size']- 2) + $arrOfSpaces['spacesBeforeWhole']
+ $arrOfSpaces['spacesBeforeDec']+ $arrOfSpaces['spacesBeforeDate1']+ $arrOfSpaces['spacesBeforeCut1'];
$problem->conflictEnd = $problem->conflictStart + 1;