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/Delete.php';
00027
00028
00029
00030
00041
00042 class FF_Action_Delete_Loan extends FF_Action_Delete {
00043
00044
00051 function run()
00052 {
00053
00054 if ($this->currentActionId == ACTION_DELETE_RESERVATION_SUBMIT) {
00055 $this->o_model->fillById(FF_Request::getParam('objectId', 'pg'));
00056
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
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
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
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
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 ?>