00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 require_once FASTFRAME_ROOT . 'lib/FastFrame/Action/Display.php';
00027
00028
00029
00030
00041
00042 class FF_Action_Display_Loan extends FF_Action_Display {
00043
00044
00051 function renderDisplay()
00052 {
00053 if ($this->o_model->isDeleted()) {
00054 $this->o_output->setMessage(sprintf(_('This is a deleted %s.'), $this->getSingularText()), FASTFRAME_WARNING_MESSAGE);
00055 }
00056
00057 require_once FASTFRAME_ROOT . '/lib/FastFrame/Output/Table.php';
00058 $o_table =& new FF_Output_Table('twoColumn');
00059 $o_table->setTableHeaderText($this->getPageName());
00060 $o_table->setTableHeaders($this->getTableData());
00061 $o_table->setAlternateRowColors(true);
00062 $o_table->render();
00063 $o_tableWidget =& $o_table->getWidgetObject();
00064
00065
00066 if (FF_Request::getParam('isReceipt', 'g', false)) {
00067 if ($this->o_model->getType() != LOANS_TYPE_RESERVATION) {
00068 $this->o_output->o_tpl->assign('css', '.color2 { background-color: #6aa652; }');
00069 }
00070 }
00071
00072 $this->o_output->o_tpl->append('content_middle', $o_tableWidget->fetch());
00073 $this->renderAdditionalLinks();
00074 if (FF_Request::getParam('isReceipt', 'g', false) &&
00075 (($this->o_model->getType() == LOANS_TYPE_RESERVATION &&
00076 $this->o_registry->getConfigParam('checkout/email_borrower_on_reservation')) ||
00077 ($this->o_model->getType() == LOANS_TYPE_LOAN &&
00078 $this->o_registry->getConfigParam('checkout/email_borrower_on_loan')))) {
00079 $this->sendConfirmationToBorrower();
00080 }
00081 }
00082
00083
00084
00085
00092 function renderAdditionalLinks()
00093 {
00094 $s_actionId = FF_Request::getParam('returnActionId', 'g');
00095 if (FF_Request::getParam('isPopup', 'g', false)) {
00096 $this->o_output->o_tpl->append('page_links', $this->o_output->link(
00097 '#', _('Close Window'), array('onclick' => 'self.close();')));
00098 }
00099 else {
00100 if ($s_actionId == ACTION_LIST_BORROWER_LOANS ||
00101 $s_actionId == ACTION_LIST_ITEM_LOANS ||
00102 $s_actionId == ACTION_LIST_GROUP_LOANS) {
00103 $s_linkText = sprintf(_('Return to Loan History for %s'), FF_Request::getParam('objectDesc', 's'));
00104 }
00105 elseif ($s_actionId == ACTION_DISPLAY_SUMMARY) {
00106 $s_linkText = false;
00107 }
00108 elseif ($s_actionId == ACTION_SHOP_SUMMARY) {
00109 $s_linkText = _('Return to Summary');
00110 }
00111 else {
00112 $s_linkText = sprintf(_('Return to %s List'), $this->getSingularText());
00113 }
00114
00115 if ($s_linkText) {
00116 $this->o_output->o_tpl->append('page_links', $this->o_output->link(
00117 FastFrame::selfURL(array('actionId' => $s_actionId)), $s_linkText));
00118 }
00119 }
00120
00121 if ((FF_Request::getParam('isReceipt', 'g', false) ||
00122 FF_Request::getParam('isPopup', 'g', false))) {
00123 $this->o_output->o_tpl->append('page_links', $this->o_output->link(
00124 '#', _('Print'), array('onclick' => 'self.print();')));
00125 }
00126 }
00127
00128
00129
00130
00137 function renderSearchBox()
00138 {
00139 return;
00140 }
00141
00142
00143
00144
00153 function getTableData($in_isEmail = false)
00154 {
00155 require_once dirname(__FILE__) . '/../Output/Checkout.php';
00156 $o_chkoutOutput =& new FF_Output_Checkout();
00157 $a_headers = array();
00158 if (!$in_isEmail && FF_Request::getParam('returnActionId', 'g') != ACTION_SHOP_SUMMARY) {
00159 $a_headers[] = array(
00160 'title' => _('Borrower:'),
00161 'data' => $o_chkoutOutput->getLinkedBorrower($this->o_model->getBorrowerId(), false,
00162 $this->o_model->getBorrowerName()),
00163 'dataIsSafe' => true,
00164 );
00165 }
00166
00167 if ($this->o_model->getType() == LOANS_TYPE_LOAN ||
00168 $this->o_model->getType() == LOANS_TYPE_RESERVATION) {
00169 $a_headers[] = array(
00170 'title' => _('Start Date:'),
00171 'data' => $this->o_model->getFormattedStartDate(),
00172 );
00173 $a_headers[] = array(
00174 'title' => _('Due Date:'),
00175 'data' => $this->o_model->getFormattedDueDate(),
00176 );
00177
00178 $a_headers[] = array(
00179 'title' => _('Processed By:'),
00180 'data' => $this->o_model->getUserFullName(),
00181 );
00182 }
00183
00184 $a_headers[] = array(
00185 'title' => sprintf(_('%s ID:'), $this->getSingularText()),
00186 'data' => $this->o_model->getId(),
00187 );
00188
00189 if ($this->o_registry->getConfigParam('checkout/use_is_complete') &&
00190 ($this->o_model->getType() == LOANS_TYPE_CART ||
00191 $this->o_model->getType() == LOANS_TYPE_RESERVATION) &&
00192 FF_Request::getParam('returnActionId', 'g') != ACTION_SHOP_SUMMARY &&
00193 !FF_Request::getParam('isReceipt', 'g', false)) {
00194 $a_headers[] = array(
00195 'title' => _('Is Complete:'),
00196 'data' => $this->_boolToString($this->o_model->getIsComplete(), $in_isEmail),
00197 'dataIsSafe' => true,
00198 );
00199 }
00200
00201 if (count($a_items = $this->o_model->getAllItems()) == 0) {
00202 $tmp_data = sprintf(_('No Items Are In This %s'), $this->getSingularText());
00203 $tmp_dataStyle = 'style="font-style: italic;"';
00204 }
00205 else {
00206 $tmp_dataStyle = '';
00207 $tmp_data = '';
00208 $b_allReturned = true;
00209 $b_startedHiddenDiv = false;
00210 foreach ($a_items as $a_item) {
00211 if ($this->o_model->getType() != LOANS_TYPE_LOAN) {
00212 $tmp_date = false;
00213 }
00214 elseif ($a_item['return_date'] == 0) {
00215 $tmp_date = _('Not Returned');
00216 $b_allReturned = false;
00217 }
00218 else {
00219 $tmp_date = $this->o_model->formatTimestamp($a_item['return_date']);
00220 }
00221
00222 $a_item['returnDate'] = $tmp_date;
00223 $b_hideDetails = (FF_Request::getParam('returnActionId', 'g') == ACTION_SHOP_SUMMARY);
00224
00225 if (!$in_isEmail && !$b_startedHiddenDiv && $a_item['returnDate'] != 0) {
00226 $b_startedHiddenDiv = true;
00227 $tmp_data .= '<div style="cursor: pointer; padding: 2px; margin-top: 5px;" class="info color6" onclick="Element.toggle(\'returnedItems\');">' . _('Click to Show Returned Items') . '</div><div style="display: none;" id="returnedItems">';
00228 }
00229
00230 $tmp_data .= $o_chkoutOutput->getItemTable($a_item, false, $b_hideDetails, $in_isEmail);
00231 }
00232
00233 if ($b_startedHiddenDiv) {
00234 $tmp_data .= '</div>';
00235 }
00236
00237 if ($this->o_model->getType() == LOANS_TYPE_LOAN && !FF_Request::getParam('isReceipt', 'g', false)) {
00238 $a_headers[] = array(
00239 'title' => _('Return Status:'),
00240 'data' => $b_allReturned ? _('All items have been returned.') : _('Not all items have been returned.'),
00241 'dataStyle' => 'style="font-style: italic;"',
00242 );
00243 }
00244 }
00245
00246 $a_headers[] = array(
00247 'title' => _('Items:'),
00248 'data' => $tmp_data,
00249 'dataStyle' => $tmp_dataStyle,
00250 'dataIsSafe' => true,
00251 );
00252
00253 if (FF_Request::getParam('isReceipt', 'g', false) && !$in_isEmail) {
00254 $s_noticeKey = $this->o_model->getType() == LOANS_TYPE_LOAN ? 'loan_notice' : 'reservation_notice';
00255 if (!FastFrame::isEmpty($s_notice = $this->o_registry->getConfigParam("checkout/$s_noticeKey"))) {
00256 $a_headers[] = array(
00257 'title' => _('Legal Notice:'),
00258 'data' => $s_notice,
00259 'dataIsSafe' => true,
00260 );
00261 }
00262
00263 $a_headers[] = array(
00264 'title' => _('Borrower Signature:'),
00265 'data' => '',
00266 );
00267 }
00268
00269 if ($this->o_perms->hasPerm('can_view_transaction_comments') &&
00270 !FF_Request::getParam('isReceipt', 'g', false) && !$in_isEmail) {
00271 require_once dirname(__FILE__) . '/../Model/Comment.php';
00272 $o_commentModel =& new FF_Model_Comment();
00273 foreach ($o_commentModel->getCommentsByTransactionId($this->o_model->getId()) as $a_data) {
00274 $o_commentModel->reset();
00275 $o_commentModel->importFromArray($a_data);
00276 $a_headers[] = array(
00277 'title' => _('Comment:'),
00278 'data' => $o_chkoutOutput->getCommentTable(array('o_comment' => &$o_commentModel), false),
00279 'dataIsSafe' => true,
00280 );
00281 }
00282 }
00283
00284 if ($this->o_perms->hasPerm('can_view_transaction_history') &&
00285 !FF_Request::getParam('isReceipt', 'g', false) && !$in_isEmail) {
00286 $a_headers[] = array(
00287 'title' => _('History:'),
00288 'data' => $o_chkoutOutput->getLoanHistory($this->o_model->getId()),
00289 'dataIsSafe' => true,
00290 );
00291 }
00292
00293 return $a_headers;
00294 }
00295
00296
00297
00298
00305 function getSingularText()
00306 {
00307 if ($this->o_model->getType() == LOANS_TYPE_LOAN) {
00308 return _('Loan');
00309 }
00310 elseif ($this->o_model->getType() == LOANS_TYPE_RESERVATION) {
00311 return _('Reservation');
00312 }
00313 else {
00314 return _('Cart');
00315 }
00316 }
00317
00318
00319
00320
00327 function getPageName()
00328 {
00329 if (FF_Request::getParam('isReceipt', 'g', false)) {
00330 return sprintf(_('%s Receipt'), $this->getSingularText());
00331 }
00332 else {
00333 return sprintf(_('%s Display'), $this->getSingularText());
00334 }
00335 }
00336
00337
00338
00339
00346 function sendConfirmationToBorrower()
00347 {
00348 $s_email = $this->o_model->getBorrowerEmail();
00349 if (!empty($s_email)) {
00350 $a_headers = array();
00351 $a_headers['Subject'] = sprintf(_('Your %s Confirmation'), $this->getSingularText());
00352 $a_headers['From'] = $this->o_registry->getConfigParam('mailer/default_from');
00353 $a_data = $this->getTableData(true);
00354 $s_body = sprintf(_('%s, below is a confirmation of your %s.'), $this->o_model->getBorrowerName(),
00355 strtolower($this->getSingularText()));
00356 $s_body .= "\n\n";
00357 foreach ($a_data as $a_element) {
00358 $s_body .= $a_element['title'] . ' ' . $a_element['data'] . "\n";
00359 }
00360
00361 require_once 'Mail.php';
00362 $o_mail =& Mail::factory($this->o_registry->getConfigParam('mailer/type'),
00363 $this->o_registry->getConfigParam('mailer/params'));
00364 if (PEAR::isError($o_mail)) {
00365 return false;
00366 }
00367 else {
00368 return $o_mail->send($s_email, $a_headers, $s_body);
00369 }
00370 }
00371 else {
00372 return false;
00373 }
00374 }
00375
00376
00377
00378
00389 function _boolToString($in_bool, $in_isEmail)
00390 {
00391 if ($in_isEmail) {
00392 return $in_bool ? _('Yes') : _('No');
00393 }
00394 else {
00395 return $in_bool ?
00396 $this->o_output->imgTag('select.gif', 'actions', array('title' => _('Yes'))) :
00397 $this->o_output->imgTag('cancel.gif', 'actions', array('title' => _('No')));
00398 }
00399 }
00400
00401
00402 }
00403 ?>