LoanDelete.php

Go to the documentation of this file.
00001 <?php
00003 // {{{ license
00004 
00005 // +----------------------------------------------------------------------+
00006 // | FastFrame Application Framework                                      |
00007 // +----------------------------------------------------------------------+
00008 // | Copyright (c) 2002-2006 The Codejanitor Loan                        |
00009 // +----------------------------------------------------------------------+
00010 // | This source file is subject to the GNU Lesser Public License (LGPL), |
00011 // | that is bundled with this package in the file LICENSE, and is        |
00012 // | available at through the world-wide-web at                           |
00013 // | http://www.fsf.org/copyleft/lesser.html                              |
00014 // | If you did not receive a copy of the LGPL and are unable to          |
00015 // | obtain it through the world-wide-web, you can get it by writing the  |
00016 // | Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
00017 // | MA 02111-1307, USA.                                                  |
00018 // +----------------------------------------------------------------------+
00019 // | Authors: Jason Rust <jrust@codejanitor.com>                          |
00020 // | Authors: Greg Gilbert <ggilbert@codejanitor.com>                     |
00021 // +----------------------------------------------------------------------+
00022 
00023 // }}}
00024 // {{{ requires
00025 
00026 require_once FASTFRAME_ROOT . 'lib/FastFrame/Action/Delete.php';
00027 
00028 // }}}
00029 // {{{ class FF_Action_Delete_Loan
00030 
00041 // }}}
00042 class FF_Action_Delete_Loan extends FF_Action_Delete {
00043     // {{{ run()
00044 
00051     function run()
00052     {
00053         // Have to fill the model before it is deleted so we will have info to email
00054         if ($this->currentActionId == ACTION_DELETE_RESERVATION_SUBMIT) {
00055             $this->o_model->fillById(FF_Request::getParam('objectId', 'pg'));
00056             // If not force overriding check rules to make sure it is ok to proceed
00057             if (!($this->o_perms->hasPerm('can_force_override') && FF_Request::getParam('forceOverride', 'p', false))) {
00058                 $o_result = new FF_Result();
00059                 require_once dirname(__FILE__) . '/../Model/Rule.php';
00060                 $o_rule =& new FF_Model_Rule();
00061                 $o_rule->validateRulesForItems($this->o_model->getAllItems(true, true), $this->o_model, $o_result, RULES_ACTION_DELETE);
00062                 if (!$o_result->isSuccess()) {
00063                     $o_result->addMessage($this->getProblemMessage());
00064                     $this->o_output->setMessage($o_result->getMessages(), FASTFRAME_ERROR_MESSAGE);
00065                     $this->o_nextAction->setNextActionId(ACTION_DELETE_RESERVATION);
00066                     return $this->o_nextAction;
00067                 }
00068             }
00069         }
00070 
00071         return parent::run();
00072     }
00073 
00074     // }}}
00075     // {{{ getSingularText()
00076 
00083     function getSingularText()
00084     {
00085         if ($this->currentActionId == ACTION_DELETE_RESERVATION_SUBMIT) {
00086             return _('reservation');
00087         }
00088         else {
00089             return _('cart');
00090         }
00091     }
00092 
00093     // }}}
00094     // {{{ setSuccessActionId()
00095 
00102     function setSuccessActionId()
00103     {
00104         $this->o_nextAction->setNextActionId(FF_Request::getParam('returnActionId', 'gp'));
00105         if ($this->currentActionId == ACTION_DELETE_RESERVATION_SUBMIT &&
00106             $this->o_registry->getConfigParam('checkout/email_reservation_deleted')) {
00107             $this->sendNoticeToBorrower();
00108         }
00109     }
00110 
00111     // }}}
00112     // {{{ checkPerms()
00113 
00120     function checkPerms()
00121     {
00122         switch ($this->currentActionId) {
00123             case ACTION_DELETE_RESERVATION_SUBMIT:
00124                 if ($this->o_perms->hasPerm('can_delete_reservation')) {
00125                     return true;
00126                 }
00127                 elseif ($this->o_perms->hasPerm('can_borrower_delete_reservation') &&
00128                         $this->o_model->getBorrowerId() == FF_Request::getParam('chkoutBorrowerId', 's')) {
00129                     return true;
00130                 }
00131                 else {
00132                     $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00133                     $this->o_output->setMessage(_('You do not have permission to delete reservations'), FASTFRAME_ERROR_MESSAGE);
00134                     return false;
00135                 }
00136             break;
00137             case ACTION_DELETE:
00138                 if (($this->o_perms->hasPerm('can_delete_cart'))) {
00139                     return true;
00140                 }
00141                 else {
00142                     $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00143                     $this->o_output->setMessage(_('You do not have permission to delete carts'), FASTFRAME_ERROR_MESSAGE);
00144                     return false;
00145                 }
00146             break;
00147             default:
00148                 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00149                 $this->o_output->setMessage(_('Could not determine the intended action'), FASTFRAME_ERROR_MESSAGE);
00150                 return false;
00151             break;
00152         }
00153     }
00154 
00155     // }}}
00156     // {{{ sendNoticeToBorrower()
00157 
00165     function sendNoticeToBorrower()
00166     {
00167         $s_email = $this->o_model->getBorrowerEmail();
00168         if (!empty($s_email)) {
00169             $a_headers = array();
00170             $a_headers['Subject'] = _('Reservation Cancelled');
00171             $a_headers['From'] = $this->o_registry->getConfigParam('mailer/default_from');
00172             $s_body = sprintf(_('%s, your reservation has been cancelled.'), $this->o_model->getBorrowerName());
00173             $s_body .= "\n\n" . _('Reason given for cancellation:') . "\n";
00174             if (!FastFrame::isEmpty(FF_Request::getParam('deleteComment', 'p'))) {
00175                 $s_body .= FF_Request::getParam('deleteComment', 'p') . "\n\n";
00176             }
00177             else {
00178                 $s_body .= _('No reason was given.') . "\n\n";
00179             }
00180 
00181             $s_body .= _('Start Date:') . ' ' . $this->o_model->getFormattedStartDate() . "\n";
00182             $s_body .= _('Due Date:') . ' ' . $this->o_model->getFormattedDueDate() . "\n";
00183 
00184             if (count($a_items = $this->o_model->getAllItems()) == 0) {
00185                 $tmp_data = _('No Items Are In This Reservation');
00186             }
00187             else {
00188                 $tmp_data = '';
00189                 require_once dirname(__FILE__) . '/../Output/Checkout.php';
00190                 $o_chkoutOutput =& new FF_Output_Checkout();
00191                 foreach ($a_items as $a_item) {
00192                     $tmp_data .= $o_chkoutOutput->getItemTable($a_item, false, false, true);
00193                 }
00194             }
00195                 
00196             $s_body .= _('Items:') . ' ' . $tmp_data . "\n";
00197 
00198             require_once 'Mail.php';
00199             $o_mail =& Mail::factory($this->o_registry->getConfigParam('mailer/type'),
00200                     $this->o_registry->getConfigParam('mailer/params'));
00201             if (PEAR::isError($o_mail)) {
00202                 return false;
00203             }
00204             else {
00205                 return $o_mail->send($s_email, $a_headers, $s_body);
00206             }
00207         }
00208         else {
00209             return false;
00210         }
00211     }
00212 
00213     // }}}
00214 }
00215 ?>

Generated on Fri Jun 23 11:38:16 2006 for FastFrame by  doxygen 1.4.4