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 require_once FASTFRAME_ROOT . 'lib/FastFrame/Action/Form.php';
00026
00027
00028
00029
00040
00041 class FF_Action_Form_Borrower extends FF_Action_Form {
00042
00043
00050 function renderAdditionalLinks()
00051 {
00052 if (FF_Request::getParam('returnActionId', 'g', false) !== false) {
00053
00054 FF_Request::setParam('borrower_returnActionId', FF_Request::getParam('returnActionId', 'g'), 's');
00055 }
00056
00057 $this->o_output->o_tpl->append('page_links', $this->o_output->link(
00058 FastFrame::selfURL(array('actionId' => FF_Request::getParam('borrower_returnActionId', 's'))),
00059 sprintf(_('Return to %s List'), $this->getSingularText())));
00060 }
00061
00062
00063
00064
00072 function createFormElements()
00073 {
00074 $this->o_form->addElement('hidden', 'actionId');
00075 $this->o_form->addElement('hidden', 'objectId');
00076 $this->o_form->addElement('submit', 'submitbutton');
00077 $this->o_form->addElement('text', 'first_name', null, array('maxlength' => 30, 'size' => 30));
00078 $this->o_form->addElement('text', 'last_name', null, array('maxlength' => 30, 'size' => 30));
00079 $this->o_form->addElement('text', 'barcode', null, array('maxlength' => 20, 'size' => 20));
00080 $this->o_form->addElement('select', 'type', null, $this->o_registry->getConfigParam('borrower/types'));
00081 $this->o_form->addElement('text', 'email', null, array('maxlength' => 50, 'size' => 25));
00082 $this->o_form->addElement('textarea', 'comment', null, array('cols' => 35, 'rows' => 7));
00083 $this->o_form->setMaxFileSize($this->o_registry->getConfigParam('borrower/max_image_size'));
00084 $this->o_form->addElement('file', 'image');
00085 $this->o_form->addElement('checkbox', 'imageRemove');
00086 $this->o_form->addElement('hidden', 'profile_id');
00087 $this->o_form->addRule('first_name', _('First name cannot be blank.'), 'required', null, 'client');
00088 $this->o_form->addRule('last_name', _('Last name cannot be blank.'), 'required', null, 'client');
00089 $this->o_form->addRule('email', _('Invalid email address entered.'), 'email', null, 'client');
00090
00091 foreach ($this->o_registry->getConfigParam('borrower/attributes') as $s_key => $s_desc) {
00092 $s_perm = "can_view_borrower_attrib_$s_key";
00093 if ($this->o_perms->hasPerm($s_perm)) {
00094 $this->o_form->addElement('text', $this->_getAttributeName($s_key), null, array('size' => 25));
00095 }
00096 }
00097 }
00098
00099
00100
00101
00109 function fillModelWithData()
00110 {
00111 if (($tmp_model = FF_Request::getParam('selectedModel', 'g', false))) {
00112 $this->currentActionId = FF_Request::getParam('returnActionId', 's');
00113 $this->o_model->importFromArray(FF_Request::getParam('returnModel', 's'));
00114 if ($tmp_model == 'Profile') {
00115 $this->o_model->setProfileId(FF_Request::getParam('selectedId', 'g'));
00116 }
00117
00118 return true;
00119 }
00120 else {
00121 return parent::fillModelWithData();
00122 }
00123 }
00124
00125
00126
00127
00134 function getSingularText()
00135 {
00136 return _('Borrower');
00137 }
00138
00139
00140
00141
00149 function getPluralText()
00150 {
00151 return _('Borrowers');
00152 }
00153
00154
00155
00156
00165 function getTableData()
00166 {
00167 $a_headers = array();
00168 $a_headers[] = array(
00169 'title' => '* ' . _('First Name'),
00170 'titleStyle' => 'style="font-weight: bold;"',
00171 'data' => $this->o_renderer->elementToHtml('first_name'),
00172 );
00173 $a_headers[] = array(
00174 'title' => '* ' . _('Last Name'),
00175 'titleStyle' => 'style="font-weight: bold;"',
00176 'data' => $this->o_renderer->elementToHtml('last_name'),
00177 );
00178 $o_fileCache =& FF_FileCache::singleton();
00179 $tmp_path = $o_fileCache->exists(array('subdir' => 'borrower_images', 'name' => $this->o_model->getId()), true) ?
00180 $o_fileCache->getPath(array('subdir' => 'borrower_images', 'name' => $this->o_model->getId()), true, FASTFRAME_WEBPATH) :
00181 $this->o_registry->getRootFile('general/no_image.gif', 'graphics', FASTFRAME_WEBPATH);
00182 $a_headers[] = array(
00183 'title' => _('Image'),
00184 'data' => $this->o_output->imgTag($tmp_path, null, array('style' => 'vertical-align: top;')) .
00185 '<div style="margin: 5px 0px 5px 0px;">' . _('Check to Remove Current Image: ') .
00186 $this->o_renderer->elementToHtml('imageRemove') . '</div>' .
00187 $this->o_renderer->elementToHtml('image'),
00188 );
00189 $a_headers[] = array(
00190 'title' => _('Barcode'),
00191 'data' => $this->o_renderer->elementToHtml('barcode'),
00192 );
00193 $a_headers[] = array(
00194 'title' => _('Email Address'),
00195 'data' => $this->o_renderer->elementToHtml('email'),
00196 );
00197 $a_headers[] = array(
00198 'title' => _('Type'),
00199 'data' => $this->o_renderer->elementToHtml('type'),
00200 );
00201 if ($this->o_perms->hasPerm('can_edit_borrower_profile_id')) {
00202 $tmp_help = _('Associating a user\'s profile with this borrower will allow that user to log in and use the shopping module to make reservations of items. Note that a user\'s profile can only be associated with one borrower.');
00203 $a_headers[] = array(
00204 'title' => sprintf(_('Associated Profile %s'), $this->o_output->getHelpLink($tmp_help)),
00205 'data' => $this->o_model->getProfileUsername() . ' ' .
00206 $this->o_output->imgTag('view.gif', 'actions',
00207 array('title' => _('Select a Profile'), 'name' => 'selectProfile', 'type' => 'input')),
00208 );
00209 }
00210
00211
00212 foreach ($this->o_registry->getConfigParam('borrower/attributes') as $s_key => $s_desc) {
00213 $s_perm = "can_view_borrower_attrib_$s_key";
00214 if ($this->o_perms->hasPerm($s_perm)) {
00215 $a_headers[] = array(
00216 'title' => $s_desc . ':',
00217 'data' => $this->o_renderer->elementToHtml($this->_getAttributeName($s_key)),
00218 );
00219 }
00220 }
00221
00222
00223 require_once dirname(__FILE__) . '/../Output/Checkout.php';
00224 require_once dirname(__FILE__) . '/../Model/Comment.php';
00225 $o_chkoutOutput =& new FF_Output_Checkout();
00226 $o_chkoutOutput->setFormObject($this->o_form);
00227 $o_commentModel =& new FF_Model_Comment();
00228 foreach ($o_commentModel->getCommentsByTransactionId($this->o_model->getId()) as $a_data) {
00229 $o_commentModel->reset();
00230 $o_commentModel->importFromArray($a_data);
00231 $a_headers[] = array(
00232 'title' => _('Comment'),
00233 'data' => $o_chkoutOutput->getCommentTable(array('o_comment' => &$o_commentModel), true)
00234 );
00235 }
00236
00237 $a_headers[] = array(
00238 'title' => _('Add a New Comment'),
00239 'data' => $this->o_renderer->elementToHtml('comment'),
00240 );
00241
00242 return $a_headers;
00243 }
00244
00245
00246
00247
00254 function getFormConstants()
00255 {
00256
00257 if (FF_Request::getParam('submitWasSuccess', 'g', false)) {
00258 return array_merge(parent::getFormConstants(), array('comment' => ''));
00259 }
00260 else {
00261 return parent::getFormConstants();
00262 }
00263 }
00264
00265
00266
00267
00275 function getFormDefaults()
00276 {
00277 $a_fields = array();
00278 $a_fields['objectId'] = $this->o_model->getId();
00279 $a_fields['first_name'] = $this->o_model->getFirstName();
00280 $a_fields['last_name'] = $this->o_model->getLastName();
00281 $a_fields['barcode'] = $this->o_model->getBarcode();
00282 $a_fields['type'] = $this->o_model->getType();
00283 $a_fields['email'] = $this->o_model->getEmail();
00284 $a_fields['profile_id'] = $this->o_model->getProfileId();
00285 $a_fields['toRemove'] = $this->o_model->getCommentsToRemove(true);
00286
00287 foreach ($this->o_registry->getConfigParam('borrower/attributes') as $s_key => $s_desc) {
00288 $s_perm = "can_view_borrower_attrib_$s_key";
00289 if ($this->o_perms->hasPerm($s_perm)) {
00290 $a_fields[$this->_getAttributeName($s_key)] = $this->o_model->getAttribute($s_key);
00291 }
00292 }
00293
00294 return $a_fields;
00295 }
00296
00297
00298
00299
00306 function checkPerms()
00307 {
00308 switch ($this->currentActionId) {
00309 case ACTION_EDIT:
00310 if (($this->o_perms->hasPerm('can_edit_borrower'))) {
00311 return true;
00312 }
00313 else {
00314 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00315 $this->o_output->setMessage(_('You do not have permission to edit borrowers'), FASTFRAME_ERROR_MESSAGE);
00316 return false;
00317 }
00318 break;
00319 case ACTION_ADD:
00320 if (($this->o_perms->hasPerm('can_add_borrower'))) {
00321 return true;
00322 }
00323 else {
00324 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00325 $this->o_output->setMessage(_('You do not have permission to add borrowers'), FASTFRAME_ERROR_MESSAGE);
00326 return false;
00327 }
00328 break;
00329 default:
00330 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00331 $this->o_output->setMessage(_('Could not determine the intended action'), FASTFRAME_ERROR_MESSAGE);
00332 return false;
00333 break;
00334 }
00335 }
00336
00337
00338
00339
00348 function _getAttributeName($in_attr)
00349 {
00350 return 'attributes[' . $in_attr . ']';
00351 }
00352
00353
00354 }
00355 ?>