예제 #1
0
파일: locum-covers.php 프로젝트: aadl/locum
 public function __construct()
 {
     $this->start_time = time();
     parent::__construct();
     $this->locum_config = array_merge($this->locum_config, parse_ini_file('config/locum-covers.ini', true));
     $this->cli = php_sapi_name() == "cli";
     $this->xisbn_count = 0;
     $this->lookup_count = 0;
     $this->sources_count = array();
     foreach ($this->locum_config['coversources'] as $id => $value) {
         $this->sources_count[$id] = 0;
     }
 }
예제 #2
0
 /**
  * Parses item status for a particular bib item.
  *
  * @param string $bnum Bib number to query
  * @return array Returns a Locum-ready availability array
  */
 public function item_status($bnum)
 {
     $iii_server_info = self::iii_server_info();
     $avail_token = locum::csv_parser($this->locum_config['iii_custom_config']['iii_available_token']);
     $default_age = $this->locum_config['iii_custom_config']['default_age'];
     $default_branch = $this->locum_config['iii_custom_config']['default_branch'];
     $loc_codes_flipped = array_flip($this->locum_config['iii_location_codes']);
     $bnum = trim($bnum);
     // Grab Hold Numbers
     $url = $iii_server_info['nosslurl'] . '/search~24/.b' . $bnum . '/.b' . $bnum . '/1,1,1,B/marc~' . $bnum . '&FF=&1,0,';
     $hold_page_raw = utf8_encode(file_get_contents($url));
     // Reserves Regex
     $regex_r = '/(?<hold_num>\\d+) hold/';
     preg_match($regex_r, $hold_page_raw, $match_r);
     $avail_array['holds'] = $match_r['hold_num'] ? $match_r['hold_num'] : 0;
     // Order Entry Regex
     $avail_array['on_order'] = 0;
     $regex_o = '%bibOrderEntry(.*?)td(.*?)>(.*?)<%s';
     preg_match_all($regex_o, $hold_page_raw, $match_o);
     foreach ($match_o[3] as $order) {
         $order_txt = trim($order);
         preg_match('%^(.*?)cop%s', $order_txt, $order_count);
         $avail_array['on_order'] = $avail_array['on_order'] + (int) trim($order_count[1]);
         $avail_array['orders'][] = $order_txt;
     }
     $url = $iii_server_info['nosslurl'] . '/search~24/.b' . $bnum . '/.b' . $bnum . '/1,1,1,B/holdings~' . $bnum . '&FF=&1,0,';
     $avail_page_raw = utf8_encode(file_get_contents($url));
     // Holdings Regex
     $regex_h = '%field 1 -->&nbsp;(.*?)</td>(.*?)browse">(.*?)</a>(.*?)field \\% -->&nbsp;(.*?)</td>%s';
     preg_match_all($regex_h, $avail_page_raw, $matches);
     foreach ($matches[1] as $i => $location) {
         // put the item details in the array
         $location = trim($location);
         $loc_code = $loc_codes_flipped[$location];
         $call = str_replace("'", "&apos;", trim($matches[3][$i]));
         $status = trim($matches[5][$i]);
         $age = $default_age;
         $branch = $default_branch;
         if (in_array($status, $avail_token)) {
             $avail = 1;
             $due_date = 0;
         } else {
             $avail = 0;
             if (preg_match('/DUE/i', $status)) {
                 $due_arr = explode(' ', trim($status));
                 $due_date_arr = explode('-', $due_arr[1]);
                 $due_date = mktime(0, 0, 0, $due_date_arr[0], $due_date_arr[1], 2000 + (int) $due_date_arr[2]);
             } else {
                 if (preg_match('/LIB USE ONLY/i', $status)) {
                     $due_date = 0;
                     $libuse = 1;
                 } else {
                     $due_date = 0;
                 }
             }
         }
         // Determine age from location
         if (count($this->locum_config['iii_record_ages'])) {
             foreach ($this->locum_config['iii_record_ages'] as $item_age => $match_crit) {
                 if (preg_match('/^\\//', $match_crit)) {
                     if (preg_match($match_crit, $loc_code)) {
                         $age = $item_age;
                     }
                 } else {
                     if (in_array($loc_code, locum::csv_parser($match_crit))) {
                         $age = $item_age;
                     }
                 }
             }
         }
         // Determine branch from location
         if (count($this->locum_config['branch_assignments'])) {
             foreach ($this->locum_config['branch_assignments'] as $branch_code => $match_crit) {
                 if (preg_match('/^\\//', $match_crit)) {
                     if (preg_match($match_crit, $loc_code)) {
                         $branch = $branch_code;
                     }
                 } else {
                     if (in_array($loc_code, locum::csv_parser($match_crit))) {
                         $branch = $branch_code;
                     }
                 }
             }
         }
         $avail_array['items'][] = array('location' => $location, 'loc_code' => $loc_code, 'callnum' => $call, 'statusmsg' => $status, 'due' => $due_date, 'avail' => $avail, 'age' => $age, 'branch' => $branch, 'libuse' => $libuse);
     }
     return $avail_array;
 }
예제 #3
0
파일: locum.php 프로젝트: aadl/locum
 /**
  * Checks $query_value against $ini_value to see a) if its a regex or csv match.
  * It will then return TRUE if it is a match or FALSE if not.
  *
  * @param string $ini_value INI file value
  * @param string $query_value Value to be matched against $ini_value
  * @return boolean TRUE = match / FALSE = no match
  */
 public function match_ini_value($ini_value, $query_value)
 {
     if (preg_match('/^\\//', $ini_value)) {
         if (preg_match($ini_value, $query_value)) {
             return TRUE;
         }
     } else {
         if (in_array($query_value, locum::csv_parser($match_crit))) {
             return TRUE;
         }
     }
     return FALSE;
 }
예제 #4
0
 /**
  * Parses item status for a particular bib item.
  *
  * @param string $bnum Bib number to query
  * @return array Returns a Locum-ready availability array
  */
 public function item_status($bnum)
 {
     $iii_webcat = $this->locum_config[ils_config][ils_server];
     $iii_webcat_port = $this->locum_config[ils_config][ils_harvest_port];
     $avail_token = locum::csv_parser($this->locum_config[ils_custom_config][iii_available_token]);
     $bnum = trim($bnum);
     $url = 'http://' . $iii_webcat . '/search/.b' . $bnum . '/.b' . $bnum . '/1,1,1,B/holdings~' . $bnum . '&FF=&1,0,';
     $avail_page_raw = utf8_encode(file_get_contents($url));
     // Holdings Regex
     $regex_h = '%field 1 -->&nbsp;(.*?)</td>(.*?)browse">(.*?)</a>(.*?)field \\% -->&nbsp;(.*?)</td>%s';
     preg_match_all($regex_h, $avail_page_raw, $matches);
     $avail_temp[location] = $matches[1];
     $avail_temp[callnum] = $matches[3];
     $avail_temp[status] = $matches[5];
     // Reserves Regex
     $regex_r = '%<div>[\\r\\n](.*?)holds on%U';
     preg_match($regex_r, $avail_page_raw, $match_r);
     $item_status_result[holds] = (int) trim($match_r[1]) ? trim($match_r[1]) : 0;
     // Order Entry Regex
     $regex_o = '%bibOrderEntry(.*?)td(.*?)>(.*?)<%s';
     preg_match($regex_o, $avail_page_raw, $match_o);
     $order_entry_msg = trim($match_o[3]);
     $item_status_result[order] = $order_entry_msg ? $order_entry_msg : '';
     $total_avail = 0;
     foreach ($matches[3] as $num => $cnum) {
         $cnum = trim($cnum);
         $item_status = trim($matches[5][$num]);
         $location = trim($matches[1][$num]);
         if (in_array($item_status, $avail_token)) {
             $avail[$cnum][$location][avail]++;
             $total_avail++;
         } else {
             if (preg_match('/DUE/i', $item_status)) {
                 $due_arr = explode(' ', trim($item_status));
                 $due_date_arr = explode('-', $due_arr[1]);
                 $due_date = mktime(0, 0, 0, $due_date_arr[0], $due_date_arr[1], 2000 + (int) $due_date_arr[2]);
                 $avail[$cnum][$location][due][] = $due_date;
                 sort($avail[$cnum][$location][due]);
             }
         }
     }
     $item_status_result[total] = count($matches[3]);
     $item_status_result[copies] = (int) $total_avail;
     $item_status_result[details] = $avail;
     return $item_status_result;
 }
예제 #5
0
 /**
  * Parses item status for a particular bib item.
  *
  * @param string $bnum Bib number to query
  * @return array Returns a Locum-ready availability array
  */
 public function item_status($bnum, $skiporder = NULL)
 {
     $iii_server_info = self::iii_server_info();
     $avail_token = locum::csv_parser($this->locum_config['iii_custom_config']['iii_available_token']);
     $default_age = $this->locum_config['iii_custom_config']['default_age'];
     $default_branch = $this->locum_config['iii_custom_config']['default_branch'];
     $loc_codes_flipped = array_flip($this->locum_config['iii_location_codes']);
     $bnum = trim($bnum);
     if ($skiporder) {
         $holds = 0;
         $xmlopacurl = $iii_server_info['nosslurl'] . '/xmlopac/.b' . $bnum . '?noexclude=WXROOT.Heading.Title.IIIRECORD';
         $record = simplexml_load_file($xmlopacurl);
         if (!$record) {
             return FALSE;
         }
         $labels = $record->xpath('//LABEL');
         foreach ($labels as $label) {
             if ($label[0] == 'Hold') {
                 $holds++;
             }
         }
         $avail_array['holds'] = $holds;
     } else {
         // Grab Hold Numbers
         $url = $iii_server_info['nosslurl'] . '/search~S24/.b' . $bnum . '/.b' . $bnum . '/1,1,1,B/marc~' . $bnum . '&FF=&1,0,';
         $hold_page_raw = utf8_encode(file_get_contents($url));
         // Reserves Regex
         $regex_r = '/([\\d]+) holds? on first copy returned/';
         preg_match($regex_r, $hold_page_raw, $match_r);
         $avail_array['holds'] = $match_r[1] ? $match_r[1] : 0;
         // Order Entry Regex
         $avail_array['on_order'] = 0;
         $regex_o = '%bibOrderEntry(.*?)td(.*?)>(.*?)<%s';
         preg_match_all($regex_o, $hold_page_raw, $match_o);
         foreach ($match_o[3] as $order) {
             $order_txt = trim($order);
             preg_match('%^(.*?)cop%s', $order_txt, $order_count);
             $avail_array['on_order'] = $avail_array['on_order'] + (int) trim($order_count[1]);
             $avail_array['orders'][] = $order_txt;
         }
     }
     $url = $iii_server_info['nosslurl'] . '/search~S24/.b' . $bnum . '/.b' . $bnum . '/1,1,1,B/holdings~' . $bnum . '&FF=&1,0,';
     $avail_page_raw = utf8_encode(file_get_contents($url));
     $row_count = preg_match_all('%<tr.+?bibItemsEntry.+?>(.+?)</tr>%s', $avail_page_raw, $rowmatch);
     for ($i = 0; $i < $row_count; $i++) {
         // Grab all table cells in the Entry
         $cellmatch = '';
         preg_match_all('%<td.+?</td>%s', $rowmatch[1][$i], $cellmatch);
         // Strip td cells to plain text content
         foreach ($cellmatch[0] as &$celltext) {
             $celltext = trim(str_replace('&nbsp;', ' ', strip_tags($celltext)));
         }
         $item = array();
         $item['location'] = $cellmatch[0][0];
         // First cell is location
         $item['callnum'] = str_replace("'", "&apos;", $cellmatch[0][1]);
         // Second cell is call number
         $item['statusmsg'] = $cellmatch[0][2];
         // Third cell is status
         $item['loc_code'] = $loc_codes_flipped[$item['location']];
         $item['age'] = $default_age;
         $item['branch'] = $default_branch;
         $item['due'] = 0;
         // Check for suppress location code
         foreach ($this->locum_config['suppress_locations'] as $suppress_location) {
             if (preg_match($suppress_location, $item['loc_code'])) {
                 // don't include this item in the items array
                 continue 2;
             }
         }
         // Special handling for Tools
         if ($item['location'] == 'Downtown 1st Floor Tools Shelf') {
             if ($item['statusmsg'] == 'AVAILABLE') {
                 $item['statusmsg'] = 'IN TRANSIT';
             } else {
                 if ($item['statusmsg'] == 'ON SHELF') {
                     $item['statusmsg'] = 'AVAILABLE';
                 } else {
                     if ($item['statusmsg'] == 'Westgate ON SHELF') {
                         $item['location'] = 'Westgate Tools Shelf';
                         $item['loc_code'] = 'watls';
                         $item['statusmsg'] = 'AVAILABLE';
                     }
                 }
             }
         }
         // Grab Copy number from call number field
         if (preg_match('/ c\\.([\\d]+)$/', $item['callnum'], $matches)) {
             $item['copynum'] = $matches[1];
             $cn_len = strlen($matches[0]);
             $item['callnum'] = substr($item['callnum'], 0, -$cn_len);
             // remove copy number from callnum field
         }
         if (in_array(strtolower($item['statusmsg']), $avail_token)) {
             $item['avail'] = 1;
         } else {
             $item['avail'] = 0;
             if (preg_match('/DUE/i', $item['statusmsg'])) {
                 $due_arr = explode(' ', trim($item['statusmsg']));
                 $due_date_arr = explode('-', $due_arr[1]);
                 $item['due'] = mktime(0, 0, 0, $due_date_arr[0], $due_date_arr[1], 2000 + (int) $due_date_arr[2]);
                 // Remove additional text from status line
                 $item['statusmsg'] = $due_arr[0] . ' ' . $due_arr[1];
             } else {
                 if (strpos($item['statusmsg'], 'LIB USE ONLY') !== FALSE) {
                     $item['libuse'] = 1;
                 }
             }
         }
         // Determine age from location
         if (count($this->locum_config['iii_record_ages'])) {
             foreach ($this->locum_config['iii_record_ages'] as $item_age => $match_crit) {
                 if (preg_match('/^\\//', $match_crit)) {
                     if (preg_match($match_crit, $item['loc_code'])) {
                         $item['age'] = $item_age;
                     }
                 } else {
                     if (in_array($item['loc_code'], locum::csv_parser($match_crit))) {
                         $item['age'] = $item_age;
                     }
                 }
             }
         }
         // Determine branch from location
         if (count($this->locum_config['branch_assignments'])) {
             foreach ($this->locum_config['branch_assignments'] as $branch_code => $match_crit) {
                 if (preg_match('/^\\//', $match_crit)) {
                     if (preg_match($match_crit, $item['loc_code'])) {
                         $item['branch'] = $branch_code;
                     }
                 } else {
                     if (in_array($item['loc_code'], locum::csv_parser($match_crit))) {
                         $item['branch'] = $branch_code;
                     }
                 }
             }
         }
         // Override Location Name
         if (count($this->locum_config['location_overrides'])) {
             foreach ($this->locum_config['location_overrides'] as $location_override) {
                 if (strpos($location_override, $item['location'] . '|') === 0) {
                     $item['location'] = str_replace($item['location'] . '|', '', $location_override);
                     break;
                 }
             }
         }
         if (stripos($item['statusmsg'], 'display') !== FALSE) {
             $item['location'] = $item['statusmsg'];
         }
         $avail_array['items'][] = $item;
     }
     return $avail_array;
 }