public function executeDeleteSpecCodes(sfWebRequest $request) { if (!$this->getUser()->isAtLeast(Users::MANAGER)) { $this->forwardToSecureAction(); } $this->forward404Unless($request->hasParameter('id'), 'No id given'); if (!$this->getUser()->isAtLeast(Users::ADMIN) && !Doctrine::getTable('CollectionsRights')->findOneByCollectionRefAndUserRef($request->getParameter('id'), $this->getUser()->getId())) { $this->forwardToSecureAction(); } $item = Doctrine::getTable('Collections')->find($request->getParameter('id')); $this->forward404Unless($item, 'No such item'); try { $item->setCodePrefix(Doctrine::getTable('Collections')->getDefaultValueOf('code_prefix')); $item->setCodePrefixSeparator(Doctrine::getTable('Collections')->getDefaultValueOf('code_prefix_separator')); $item->setCodeSuffix(Doctrine::getTable('Collections')->getDefaultValueOf('code_suffix')); $item->setCodeSuffixSeparator(Doctrine::getTable('Collections')->getDefaultValueOf('code_suffix_separator')); $item->setCodeAutoIncrement(Doctrine::getTable('Collections')->getDefaultValueOf('code_auto_increment')); $item->setCodeAutoIncrement(Doctrine::getTable('Collections')->getDefaultValueOf('code_auto_increment_for_insert_only')); $item->save(); return $this->renderText('ok'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); return $this->renderText($e->getMessage()); } }
public function executeIndex(sfWebRequest $request) { $this->form = new RegisterForm(); $this->form->addLoginInfos(0); $this->form->addComm(0); if ($request->isMethod('post') && $request->getParameter('users', '') !== '') { $captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field')); $this->form->bind(array_merge($request->getParameter('users'), array('captcha' => $captcha))); if ($this->form->isValid()) { try { $this->user = $this->form->save(); $this->user->addUserWidgets(); $userInfos = $request->getParameter('users'); $mail = ''; if (isset($userInfos['RegisterCommForm'][0]['entry'])) { $mail = $userInfos['RegisterCommForm'][0]['entry']; } $username = ''; if (isset($userInfos['RegisterLoginInfosForm'][0]['user_name'])) { $username = $userInfos['RegisterLoginInfosForm'][0]['user_name']; } $base_params = array('physical' => $this->user->getIsPhysical(), 'name' => $this->user->getFamilyName(), 'title' => $this->user->getTitle()); $suppl_params = array('mail' => $mail, 'username' => $username); // send an email to the registered user $this->getUser()->setCulture($this->form->getValue('selected_lang')); $this->sendConfirmationMail(array_merge($base_params, $suppl_params)); $this->redirect('register/succeeded?' . http_build_query($base_params)); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } }
public function executePeople(sfWebRequest $request) { if ($this->getUser()->isA(Users::REGISTERED_USER)) { $this->forwardToSecureAction(); } if ($request->hasParameter('id')) { $this->cataloguepeople = Doctrine::getTable('CataloguePeople')->find($request->getParameter('id')); } else { $this->cataloguepeople = new CataloguePeople(); $this->cataloguepeople->setRecordId($request->getParameter('rid')); $this->cataloguepeople->setReferencedRelation($request->getParameter('table')); } $this->form = new CataloguePeopleForm($this->cataloguepeople, array('table' => $request->getParameter('table'))); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('catalogue_people')); if ($this->form->isValid()) { try { $this->form->save(); return $this->renderText('ok'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error, 'Darwin 2 :'); } } } $this->form->forceSubType(); $this->searchForm = new PeopleFormFilter(array('table' => $request->getParameter('table'))); }
public function executeAdd(sfWebRequest $request) { if (!$this->getUser()->isA(Users::ADMIN)) { if ($request->getParameter('table') == 'loans' || $request->getParameter('table') == 'loan_items') { $loan = Doctrine::getTable($request->getParameter('table') == 'loans' ? 'Loans' : 'LoanItems')->find($request->getParameter('id')); if (!Doctrine::getTable('loanRights')->isAllowed($this->getUser()->getId(), $request->getParameter('table') == 'loans' ? $loan->getId() : $loan->getLoanRef())) { $this->forwardToSecureAction(); } } elseif ($this->getUser()->isA(Users::REGISTERED_USER)) { $this->forwardToSecureAction(); } } if ($request->hasParameter('id')) { $r = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->find($request->getParameter('id')); $this->forward404Unless($r, 'No such item'); if (!$this->getUser()->isA(Users::ADMIN)) { if ($request->getParameter('table') == 'specimens') { if (!Doctrine::getTable('Specimens')->hasRights('spec_ref', $request->getParameter('id'), $this->getUser()->getId())) { $this->forwardToSecureAction(); } } } } $this->property = null; if ($request->hasParameter('rid')) { $this->property = Doctrine::getTable('Properties')->find($request->getParameter('rid')); } if (!$this->property) { $this->property = new Properties(); $this->property->setRecordId($request->getParameter('id')); $this->property->setReferencedRelation($request->getParameter('table')); if ($request->hasParameter('model')) { $this->property->setPropertyTemplate($request->getParameter('model')); } } $this->form = new PropertiesForm($this->property, array('ref_relation' => $request->getParameter('table'), 'hasmodel' => $request->getParameter('model') ? true : false)); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('properties')); if ($this->form->isValid()) { try { $this->form->save(); return $this->renderText('ok'); } catch (Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } }
public function save(Doctrine_Connection $conn = null) { parent::save($conn); foreach ($this->array_object as $object) { $object->setReferencedRelation($this->getTable()->getTableName()); $object->setRecordId($this->id); try { $object->save(); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $this->array_errors[] = "Unit " . $this->getTable()->getTableName() . " object were not saved: " . $e->getMessage() . ";"; } } return $this->array_errors; }
public function addTool($tool) { // Define a new object and try to add and save new value passed $newTool = new CollectingTools(); $newTool->setTool($tool); try { $newTool->save(); } catch (Doctrine_Exception $ne) { // Return database error if occurs $e = new DarwinPgErrorParser($ne); return $e->getMessage(); } // Return id of new record saved return $newTool->getId(); }
public function executeVernacularnames(sfWebRequest $request) { if (!$this->getUser()->isAtLeast(Users::ENCODER)) { $this->forwardToSecureAction(); } $this->forward404Unless($request->hasParameter('id') && $request->hasParameter('table')); $this->ref_object = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->find($request->getParameter('id')); $this->forward404Unless($this->ref_object); $this->form = new GroupedVernacularNamesForm(null, array('table' => $request->getParameter('table'), 'id' => $request->getParameter('id'))); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('grouped_vernacular')); if ($this->form->isValid()) { try { $this->form->save(); return $this->renderText('ok'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } }
public function executeCreate(sfWebRequest $request) { $this->forward404Unless($request->isMethod(sfRequest::POST)); $this->mode = 'new'; if ($this->getUser()->getDbUserType() < Users::MANAGER) { $this->forwardToSecureAction(); } $this->form = new UsersForm(null, array("db_user_type" => $this->getUser()->getDbUserType(), 'mode' => $this->mode)); $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { try { $this->user = $this->form->save(); $this->user->addUserWidgets(); $this->redirect('user/edit?id=' . $this->user->getId()); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } $this->setTemplate('new'); }
public function executeEditMaintenance(sfWebRequest $request) { if ($this->getUser()->isA(Users::REGISTERED_USER)) { $this->forwardToSecureAction(); } //We edit a maintenance if ($request->getParameter('id', null) !== null) { $maint = Doctrine::getTable('CollectionMaintenance')->find($request->getParameter('id')); } elseif ($request->getParameter('rid', null) !== null) { $maint = new CollectionMaintenance(); $maint->setRecordId($request->getParameter('rid')); $maint->setReferencedRelation('specimens'); } $this->forward404unless($maint); $this->form = new CollectionMaintenanceForm($maint); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('collection_maintenance')); if ($this->form->isValid()) { try { $this->form->save(); return $this->renderText('ok'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } }
public function executeRelation(sfWebRequest $request) { if ($this->getUser()->isA(Users::REGISTERED_USER)) { $this->forwardToSecureAction(); } if ($request->hasParameter('id')) { $this->relation = Doctrine::getTable('PeopleRelationships')->find($request->getParameter('id')); $this->is_physical = Doctrine::getTable('People')->find($request->getParameter('ref_id'))->getIsPhysical(); } else { $this->relation = new PeopleRelationships(); $this->relation->setPerson_2Ref($request->getParameter('ref_id')); $this->is_physical = Doctrine::getTable('People')->find($request->getParameter('ref_id'))->getIsPhysical(); } $this->form = new PeopleRelationshipsForm($this->relation); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('people_relationships')); if ($this->form->isValid()) { try { $this->form->save(); return $this->renderText('ok'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); return $this->renderText($e->getMessage()); } } } }
public function executeAdd(sfWebRequest $request) { if ($this->getUser()->isA(Users::REGISTERED_USER)) { $this->forwardToSecureAction(); } $file_record = null; if ($request->hasParameter('rid')) { $file_record = Doctrine::getTable('Multimedia')->find($request->getParameter('rid')); } if (!$file_record) { $this->forward404Unless($request->hasParameter('id') && $request->hasParameter('table') && $request->hasParameter('file_id')); $file = $this->getUser()->getAttribute($request->getParameter('file_id')); $file_record = new Multimedia(); $file_record->fromArray($file); $file_record->setReferencedRelation($request->getParameter('table')); $file_record->setRecordId($request->getParameter('id')); } $this->form = new MultimediaForm($file_record); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('multimedia')); if ($this->form->isValid()) { try { if ($this->form->getObject()->isNew()) { $this->form->setRecordRef($request->getParameter('table'), $request->getParameter('id')); } $this->form->save(); $this->form->getObject()->refreshRelated(); $this->form = new MultimediaForm($this->form->getObject()); //Ugly refresh return $this->renderText('ok'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } }
public function executeDeleteSavedSearch(sfWebRequest $request) { $r = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->find($request->getParameter('id')); $this->forward404Unless($r, 'No such item'); try { $is_spec_search = $r->getIsOnlyId(); $r->delete(); if (!$request->isXmlHttpRequest()) { if ($is_spec_search) { return $this->redirect('savesearch/index?specimen=true'); } else { return $this->redirect('savesearch/index'); } } } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $this->renderText($e->getMessage()); } return $this->renderText("ok"); }
/** * Action executed when deleting an expedition by clicking on the delete link * @param sfWebRequest $request Request coming from browser */ public function executeDelete(sfWebRequest $request) { if ($this->getUser()->isA(Users::REGISTERED_USER)) { $this->forwardToSecureAction(); } // Trigger the protection against the XSS attack $request->checkCSRFProtection(); // Forward to a 404 page if the expedition to be deleted has not been found // Forward to a 404 page if notion is not defined as tool or method $this->forward404Unless($request->getParameter('notion', '') == 'method' || $request->getParameter('notion', '') == 'tool'); // Set notion parameter $this->notion = $request->getParameter('notion'); if ($this->notion == 'method') { $tool_or_method = Doctrine::getTable('CollectingMethods')->find($request->getParameter('id')); $this->forward404Unless($tool_or_method, sprintf('Object method does not exist (%s).', $request->getParameter('id'))); } else { $tool_or_method = Doctrine::getTable('CollectingTools')->find($request->getParameter('id')); $this->forward404Unless($tool_or_method, sprintf('Object tool does not exist (%s).', $request->getParameter('id'))); } // Effectively triggers the delete method of the expedition table try { $tool_or_method->delete(); $this->redirect('methods_and_tools/' . $this->notion . 'sIndex'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); if ($this->notion == 'method') { $this->form = new CollectingMethodsForm($tool_or_method); } else { $this->form = new CollectingToolsForm($tool_or_method); } $this->form->getErrorSchema()->addError($error); $this->loadWidgets(); $this->setTemplate('edit'); } }
private function saveUnit() { $this->staging_catalogue->fromArray(array("import_ref" => $this->import_id, "parent_ref" => $this->parent)); try { $result = $this->staging_catalogue->save(); foreach ($result as $key => $error) { $this->errors_reported .= $error; } $this->parent = $this->staging_catalogue->getId(); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $this->errors_reported .= "Unit " . $this->staging_catalogue->getName() . " object were not saved: " . $e->getMessage() . ";"; } }
public function executeOverview(sfWebRequest $request) { $this->loan = $this->checkRight($request->getParameter('id')); $this->form = new LoanOverviewForm(null, array('loan' => $this->loan)); if ($request->getParameter('loan_overview', '') !== '') { $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { try { $this->form->save(); return $this->redirect('loan/overview?id=' . $this->loan->getId()); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } }
public function executeAddNew(sfWebRequest $request) { if ($this->getUser()->isA(Users::REGISTERED_USER)) { $this->forwardToSecureAction(); } if ($request->hasParameter('num')) { $igs = new Igs(); $igs->setIgNum($request->getParameter('num')); try { $igs->save(); return $this->renderText($igs->getId()); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); return $error; } } }
public function executeMaintenances(sfWebRequest $request) { // Forward to a 404 page if the requested expedition id is not found $this->forward404Unless($items = explode(',', $request->getParameter('ids'))); if (!($id = doctrine::getTable('loanItems')->getLoanRef($items))) { $this->forwardToSecureAction(); } if (!$this->getUser()->isAtLeast(Users::ADMIN) && Doctrine::getTable('loanRights')->isAllowed($this->getUser()->getId(), $id) !== true) { $this->forwardToSecureAction(); } $i18n = $this->getContext()->getI18N(); $options = array('forced_action_observation_options' => array('approval' => $i18n->__('approval'), 'checked_by' => $i18n->__('Checked by'), 'organized_by' => $i18n->__('organized_by'), 'preparation' => $i18n->__('preparation'), 'received_by' => $i18n->__('Received by'), 'received_back_by' => $i18n->__('Return received by'), 'checked_back_by' => $i18n->__('Return checked by'))); $this->form = new MultiCollectionMaintenanceForm(null, $options); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('collection_maintenance')); if ($this->form->isValid()) { try { $obj = $this->form->updateObject(); $obj->setReferencedRelation('loan_items'); foreach ($items as $it) { $o = clone $obj; $o->setRecordId($it); $o->save(); } return $this->renderText('ok'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } }
public function executeRenewPwd(sfWebRequest $request) { if ($request->hasParameter('id') && $request->hasParameter('hash')) { $this->form = new RenewPwdForm(array('id' => $request->getParameter('id'), 'hash' => $request->getParameter('hash'))); $userLogin = Doctrine::getTable('UsersLoginInfos')->findOneByUserRefAndRenewHash($request->getParameter('id'), $request->getParameter('hash')); $this->forward404Unless($userLogin); } else { $this->form = new RenewPwdForm(); } if ($request->isMethod('post')) { $this->form->bind($request->getParameter('renew_pwd')); if ($this->form->isValid()) { $id = $this->form->getValue('id'); $hash = $this->form->getValue('hash'); $this->forward404If(empty($id) || empty($hash)); if (!isset($userLogin)) { $userLogin = Doctrine::getTable('UsersLoginInfos')->findOneByUserRefAndRenewHash($id, $hash); } $this->forward404Unless($userLogin); try { $userLogin->setNewPassword($this->form->getValue('new_password')); $userLogin->setRenewHash(null); $userLogin->save(); $this->redirect($this->getContext()->getConfiguration()->generatePublicUrl('renewed', array(), $request)); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } }
protected function processForm(sfWebRequest $request, sfForm $form, array $fields) { $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { try { $form->save(); return $this->redirect('staging/index?import=' . $form->getObject()->getImportRef()); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $form->getErrorSchema()->addError($error); } } }
protected function processForm(sfWebRequest $request, sfForm $form) { if ($this->getUser()->isA(Users::REGISTERED_USER)) { $this->forwardToSecureAction(); } $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { try { $form->save(); $this->redirect('taxonomy/edit?id=' . $form->getObject()->getId()); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $form->getErrorSchema()->addError($error); } } }
protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { try { $form->save(); $this->redirect('lithology/edit?id=' . $form->getObject()->getId()); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $form->getErrorSchema()->addError($error); } } }
protected function processForm(sfWebRequest $request, sfForm $form, $action = 'create') { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { try { $item = $form->save(); $this->redirect('gtu/edit?id=' . $item->getId()); } catch (Doctrine_Exception $ne) { if ($action == 'create') { //If Problem in saving embed forms set dirty state $form->getObject()->state('TDIRTY'); } $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $form->getErrorSchema()->addError($error); } } }
private function saveUnit() { $ok = true; $this->staging->fromArray(array("import_ref" => $this->import_id)); try { $result = $this->staging->save(); foreach ($result as $key => $error) { $this->errors_reported .= $error; } } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $this->errors_reported .= "Unit " . $this->name . " object were not saved: " . $e->getMessage() . ";"; $ok = false; } if ($ok) { $this->saveObjects(); $this->unit_id_ref[$this->name] = $this->staging->getId(); } }
public function executeBiblio(sfWebRequest $request) { if (!$this->getUser()->isAtLeast(Users::ENCODER)) { $this->forwardToSecureAction(); } $this->biblio = null; if ($request->hasParameter('id')) { $this->biblio = Doctrine::getTable('CatalogueBibliography')->find($request->getParameter('id')); } if (!$this->biblio) { $this->biblio = new CatalogueBibliography(); $this->biblio->setRecordId($request->getParameter('rid')); $this->biblio->setReferencedRelation($request->getParameter('table')); } $this->form = new CatalogueBibliographyForm($this->biblio); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('catalogue_bibliography')); if ($this->form->isValid()) { try { $this->form->save(); $this->form->getObject()->refreshRelated(); $this->form = new CatalogueBibliographyForm($this->form->getObject()); //Ugly refresh return $this->renderText('ok'); } catch (Doctrine_Exception $ne) { $e = new DarwinPgErrorParser($ne); $error = new sfValidatorError(new savedValidator(), $e->getMessage()); $this->form->getErrorSchema()->addError($error); } } } $this->searchForm = new BibliographyFormFilter(); }