-
Notifications
You must be signed in to change notification settings - Fork 0
/
NashvilleCarlXUpdatePatronImage.php
66 lines (55 loc) · 2.13 KB
/
NashvilleCarlXUpdatePatronImage.php
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
<?php
//////////////////// CREATE/UPDATE PATRON IMAGES FROM ID LIST ////////////////////
// echo 'SYNTAX: $ sudo php NashvilleCarlXUpdatePatronImage.php\n';
require_once 'ic2carlx_put_carlx.php';
date_default_timezone_set('America/Chicago');
$startTime = microtime(true);
$configArray = parse_ini_file('../config.pwd.ini', true, INI_SCANNER_RAW);
$patronApiWsdl = $configArray['Catalog']['patronApiWsdl'];
$patronApiDebugMode = $configArray['Catalog']['patronApiDebugMode'];
$patronApiReportMode = $configArray['Catalog']['patronApiReportMode'];
$reportPath = '../data/';
$records = array();
$fhnd = fopen($reportPath . "CARLX_MNPS_UPDATE_PATRON_IMAGE.CSV", "r");
if ($fhnd){
while (($data = fgetcsv($fhnd)) !== FALSE){
$records[] = $data;
}
}
$i = 0;
$errors = array();
foreach ($records as $patron) {
if (preg_match('/^\d{6,7}$/', $patron[0]) === 1) {
$patronGroup = "staff";
} elseif (preg_match('/^190\d{6}$/', $patron[0]) === 1) {
$patronGroup = "students";
} else {
continue;
}
$requestName = 'updateImage';
$tag = $patron[0] . ' : ' . $requestName;
$request = new stdClass();
$request->Modifiers = new stdClass();
$request->Modifiers->DebugMode = $patronApiDebugMode;
$request->Modifiers->ReportMode = $patronApiReportMode;
$request->SearchType = 'Patron ID';
$request->SearchID = $patron[0]; // Patron ID
$request->ImageType = 'Profile'; // Patron Profile Picture vs. Signature
$imageFilePath = "../data/images/" . $patronGroup . "/" . $patron[0] . ".jpg";
if (file_exists($imageFilePath)) {
$imageFileHandle = fopen($imageFilePath, "rb");
$request->ImageData = fread($imageFileHandle, filesize($imageFilePath));
fclose($imageFileHandle);
} else {
// TO DO: create IMAGE NOT AVAILABLE image
}
if (isset($request->ImageData)) {
$result = callAPI($patronApiWsdl, $requestName, $request, $tag);
}
}
// TO DO: save the errors to a file.
// $ferror = fopen($reportPath . "NashvilleCarlXUpdatePatrons.error.txt", "w");
// TO DO : THIS AIN'T RIGHT fwrite($ferror, print_r($errors));
// fclose($ferror);
print_r($errors);
?>