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/FormSubmit.php';
00027
00028
00029
00030
00042
00043 class FF_Action_FormSubmit_Item extends FF_Action_FormSubmit {
00044
00045
00053 function doMultiPageForm()
00054 {
00055 if (FF_Request::getParam('selectVendor_x', 'p', false) !== false) {
00056 $s_nextModule = 'Vendor';
00057 }
00058 elseif (FF_Request::getParam('selectCategory_x', 'p', false) !== false) {
00059 $s_nextModule = 'Category';
00060 }
00061 else {
00062 $s_nextModule = false;
00063 }
00064
00065 if ($s_nextModule) {
00066 FF_Request::setParam('returnModel', $this->o_model->exportToArray(), 's');
00067 if ($this->currentActionId == ACTION_EDIT_SUBMIT) {
00068 FF_Request::setParam('returnActionId', ACTION_EDIT, 's');
00069 }
00070 else {
00071 FF_Request::setParam('returnActionId', ACTION_ADD, 's');
00072 }
00073
00074 FF_Request::setParam('returnObjectId', $this->o_model->getId(), 's');
00075 FF_Request::setParam('returnModule', 'Item', 's');
00076 $this->o_nextAction->setNextActionId(ACTION_SELECT);
00077 $this->o_nextAction->setNextModuleId($s_nextModule);
00078 return true;
00079 }
00080 else {
00081 return false;
00082 }
00083 }
00084
00085
00086
00087
00094 function fillModelWithSubmitData()
00095 {
00096 $this->o_model->fillById(FF_Request::getParam('objectId','p'));
00097
00098
00099 if ($this->o_model->getStatus() == ITEM_STATUS_ONLOAN &&
00100 FF_Request::getParam('status','p') != ITEM_STATUS_ONLOAN) {
00101 require_once dirname(__FILE__) . '/../Model/Loan.php';
00102 $o_loanModel =& new FF_Model_Loan;
00103 $o_loanModel->setType(LOANS_TYPE_RETURN);
00104 $o_loanModel->setItemsFromString($this->o_model->getBarcode());
00105 $o_loanModel->save(true);
00106 }
00107
00108 $this->o_model->setName(FF_Request::getParam('name', 'p'));
00109 $this->o_model->setDescription(FF_Request::getParam('description', 'p'));
00110 $this->o_model->setStatus(FF_Request::getParam('status', 'p'));
00111 $this->o_model->setVendorId(FF_Request::getParam('vendor_id', 'p'));
00112 $this->o_model->setCategoryId(FF_Request::getParam('category_id', 'p'));
00113 $this->o_model->setBarcode(FF_Request::getParam('barcode', 'p'));
00114 $this->o_model->setSerialNum(FF_Request::getParam('serial_num', 'p'));
00115 $this->o_model->setStoreId(FF_Request::getParam('store_id', 'p'));
00116 $this->o_model->setShopperViewable(FF_Request::getParam('shopper_viewable', 'p'));
00117 $this->o_model->setNewComment(FF_Request::getParam('comment', 'p'));
00118 $a_remove = FF_Request::getParam('toRemove', 'p');
00119 $a_remove['comments'] = isset($a_remove['comments']) ? $a_remove['comments'] : array();
00120 $this->o_model->setCommentsToRemove($a_remove['comments']);
00121 $this->o_model->setRules(FF_Request::getParam('rules', 'p'));
00122 foreach (FF_Request::getParam('attributes', 'p', array()) as $s_key => $s_val) {
00123 $this->o_model->setAttribute($s_key, $s_val);
00124 }
00125 }
00126
00127
00128
00129
00136 function save()
00137 {
00138 $o_result =& $this->o_model->save($this->isUpdate());
00139 if ($o_result->isSuccess()) {
00140 $o_fileCache =& FF_FileCache::singleton();
00141 if (FF_Request::getParam('imageRemove', 'p', false)) {
00142 FF_Request::setParam('imageRemove', null, 'p');
00143 $o_fileCache->remove(array('subdir' => 'item_images', 'name' => $this->o_model->getId()), true);
00144 }
00145
00146 $tmp_result =& $o_fileCache->saveUploadedFile(FF_Request::getParam('image', 'f'),
00147 array('subdir' => 'item_images', 'name' => $this->o_model->getId()),
00148 $this->o_registry->getConfigParam('borrower/max_image_size'),
00149 array('image/png', 'image/gif', 'image/jpeg', 'image/pjpeg'), true);
00150 if (!$tmp_result->isSuccess()) {
00151
00152 $o_result->addMessage($tmp_result->getMessages());
00153 }
00154
00155 $o_fileCache->makeViewableFromWeb(array('subdir' => 'item_images', 'name' => $this->o_model->getId()), true);
00156
00157 $a_remove = FF_Request::getParam('toRemove', 'p');
00158 $a_remove['files'] = isset($a_remove['files']) ? $a_remove['files'] : array();
00159 foreach (array_keys($a_remove['files']) as $s_id) {
00160 unset($_POST['toRemove']['files'][$s_id]);
00161 $o_fileCache->remove(array('subdir' => 'item_files', 'id' => $this->o_model->getId(), 'name' => $s_id), true);
00162 }
00163
00164 $tmp_result =& $o_fileCache->saveUploadedFile(FF_Request::getParam('file', 'f'),
00165 array('subdir' => 'item_files', 'id' => $this->o_model->getId()),
00166 $this->o_registry->getConfigParam('item/max_file_size'),
00167 null, true);
00168 if (!$tmp_result->isSuccess()) {
00169
00170 $o_result->addMessage($tmp_result->getMessages());
00171 }
00172 }
00173
00174 return $o_result;
00175 }
00176
00177
00178
00179
00186 function validateInput()
00187 {
00188 require_once dirname(__FILE__) . '/../Validate/Item.php';
00189 $o_validate =& new FF_Validate_Item($this->o_model, $this->isUpdate());
00190 return $o_validate->validate();
00191 }
00192
00193
00194
00195
00202 function getSingularText()
00203 {
00204 return _('item');
00205 }
00206
00207
00208
00209
00216 function checkPerms()
00217 {
00218 switch ($this->currentActionId) {
00219 case ACTION_EDIT_SUBMIT:
00220 if (($this->o_perms->hasPerm('can_edit_item'))) {
00221 return true;
00222 }
00223 else {
00224 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00225 $this->o_output->setMessage(_('You do not have permission to edit items'), FASTFRAME_ERROR_MESSAGE);
00226 return false;
00227 }
00228 break;
00229 case ACTION_ADD_SUBMIT:
00230 if (($this->o_perms->hasPerm('can_add_item'))) {
00231 return true;
00232 }
00233 else {
00234 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00235 $this->o_output->setMessage(_('You do not have permission to add items'), FASTFRAME_ERROR_MESSAGE);
00236 return false;
00237 }
00238 break;
00239 default:
00240 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00241 $this->o_output->setMessage(_('Could not determine the intended action'), FASTFRAME_ERROR_MESSAGE);
00242 return false;
00243 break;
00244 }
00245 }
00246
00247
00248 }
00249 ?>