function _checkout_e($mbcode, $bcode, $due, $date, $force) { if ($date === NULL) { list($date, $err) = Date::read_e('today'); if ($err) { Fatal::internalError("Unexpected date error: " . $err); } $earliest = $latest = time(); } else { list($date, $err) = Date::read_e($date); if ($err) { return new Error($this->_loc->getText("Can't understand date: %err%", array('err' => $err->toStr()))); } $earliest = strtotime($date . " 00:00:00"); $latest = strtotime($date . " 23:59:59"); } if ($due !== NULL) { list($due, $err) = Date::read_e($due); if ($err) { return new Error($this->_loc->getText("Can't understand date: %err%", array('err' => $err->toStr()))); } } if ($earliest > time()) { return new Error($this->_loc->getText("Won't do checkouts for future dates.")); } $mbrQ = new MemberQuery(); $mbr = $mbrQ->maybeGetByBarcode($mbcode); if (!$mbr) { return new Error($this->_loc->getText("Bad member barcode: %bcode%", array('bcode' => $mbcode))); } $mbrid = $mbr->getMbrid(); if (!$force && OBIB_BLOCK_CHECKOUTS_WHEN_FINES_DUE) { $acctQ = new MemberAccountQuery(); $balance = $acctQ->getBalance($mbrid); if ($balance > 0) { return new Error($this->_loc->getText("Member owes fines: checkout not allowed")); } } $copyQ = new BiblioCopyQuery(); $copy = $copyQ->maybeGetByBarcode($bcode); if (!$copy) { return new Error($this->_loc->getText("Bad copy barcode: %bcode%", array('bcode' => $bcode))); } if ($copy->getStatusCd() == OBIB_STATUS_OUT) { if ($copy->getMbrid() == $mbrid) { # Renewal $reachedLimit = $copyQ->hasReachedRenewalLimit($mbrid, $mbr->getClassification(), $copy); if (!$force && $reachedLimit) { return new Error($this->_loc->getText("Item %bcode% has reached its renewal limit.", array('bcode' => $bcode))); } else { if (!$force && $copy->getDaysLate() > 0) { return new Error($this->_loc->getText("Item %bcode% is late and cannot be renewed.", array('bcode' => $bcode))); } else { $copy->setRenewalCount($copy->getRenewalCount() + 1); } } } else { if ($force) { list($dummy, $err) = $this->shelving_cart_e($bcode, $date, $force); if ($err) { return $err; } $copy = $copyQ->maybeGetByBarcode($bcode); if (!$copy) { Fatal::internalError("Copy disappeared mysteriously."); } } else { return new Error($this->_loc->getText("Item %bcode% is already checked out to another member.", array('bcode' => $bcode))); } } } else { $copy->setRenewalCount(0); $reachedLimit = $copyQ->hasReachedCheckoutLimit($mbrid, $mbr->getClassification(), $copy->getBibid()); if (!$force && $reachedLimit) { return new Error($this->_loc->getText("Member has reached checkout limit for this collection.")); } } $days = $copyQ->getDaysDueBack($copy); if ($days <= 0) { if ($force) { # the checkout has probably already happened, just guess - FIXME? $days = 14; } else { return new Error($this->_loc->getText("Checkouts are disallowed for this collection.")); } } if ($copy->getStatusCd() == OBIB_STATUS_ON_HOLD) { $holdQ = new BiblioHoldQuery(); $hold = $holdQ->maybeGetFirstHold($copy->getBibid(), $copy->getCopyid()); if ($hold) { // FIXME: Y2K38. Before 2038, timestamp won't be outside valid range. $holdAge = Date::daysLater($date, $hold->getHoldBeginDt()); if (OBIB_HOLD_MAX_DAYS > 0 && $holdAge > OBIB_HOLD_MAX_DAYS) { $tooOld = true; } else { $tooOld = false; } if ($tooOld || $mbrid == $hold->getMbrid()) { $holdQ->delete($hold->getBibid(), $hold->getCopyid(), $hold->getHoldid()); } else { if (!$force) { return new Error($this->_loc->getText("Item is on hold for another member.")); } } } } $oldtime = strtotime($copy->getStatusBeginDt()); if ($oldtime > $latest) { return new Error($this->_loc->getText("Can't change status to an earlier date on item %bcode%.", array('bcode' => $bcode))); } else { if ($oldtime == $latest) { return new Error($this->_loc->getText("Can't change status more than once per second on item %bcode%.", array('bcode' => $bcode))); } else { if ($oldtime < $earliest) { $time = date('Y-m-d H:i:s', $earliest); } else { $time = date('Y-m-d H:i:s', $oldtime + 1); } } } $copy->setStatusCd(OBIB_STATUS_OUT); $copy->setMbrid($mbrid); $copy->setStatusBeginDt($time); if ($due === NULL) { $copy->setDueBackDt(Date::addDays($date, $days)); } else { $copy->setDueBackDt($due); } if (!$copyQ->updateStatus($copy)) { Fatal::InternalError("Impossible copyQ update error."); } $hist = new BiblioStatusHist(); $hist->setBibid($copy->getBibid()); $hist->setCopyid($copy->getCopyid()); $hist->setStatusCd($copy->getStatusCd()); $hist->setStatusBeginDt($copy->getStatusBeginDt()); $hist->setDueBackDt($copy->getDueBackDt()); $hist->setMbrid($copy->getMbrid()); $hist->setRenewalCount($copy->getRenewalCount()); $histQ = new BiblioStatusHistQuery(); $histQ->insert($hist); }
function fetchRow() { $array = $this->_conn->fetchRow(); if ($array == false) { return false; } $hist = new BiblioStatusHist(); $hist->setBibid($array["bibid"]); $hist->setCopyid($array["copyid"]); $hist->setBiblioBarcodeNmbr($array["biblio_barcode_nmbr"]); $hist->setTitle($array["title"]); $hist->setAuthor($array["author"]); $hist->setStatusCd($array["status_cd"]); $hist->setStatusBeginDt($array["status_begin_dt"]); $hist->setMbrid($array["mbrid"]); $hist->setLastName($array["last_name"]); $hist->setFirstName($array["first_name"]); $hist->setMbrBarcodeNmbr($array["mbr_barcode_nmbr"]); $hist->setDueBackDt($array["due_back_dt"]); $hist->setRenewalCount($array["renewal_count"]); return $hist; }
if (!$copyQ->update($copy, true)) { $copyQ->close(); displayErrorPage($copyQ); } $copyQ->close(); #************************************************************************** #* Insert into biblio status history #************************************************************************** $hist = new BiblioStatusHist(); $hist->setBibid($copy->getBibid()); $hist->setCopyid($copy->getCopyid()); $hist->setStatusCd($copy->getStatusCd()); $hist->setStatusBeginDt($copy->getStatusBeginDt()); $hist->setDueBackDt($copy->getDueBackDt()); $hist->setMbrid($copy->getMbrid()); $hist->setRenewalCount($copy->getRenewalCount()); $histQ = new BiblioStatusHistQuery(); $histQ->connect(); if ($histQ->errorOccurred()) { $histQ->close(); displayErrorPage($histQ); } $histQ->insert($hist); if ($histQ->errorOccurred()) { $histQ->close(); displayErrorPage($histQ); } $histQ->close(); #************************************************************************** #* Update member's activity date #**************************************************************************