/** * @see website_BlockAction::execute() * @param f_mvc_Request $request * @param f_mvc_Response $response * @return String */ public function execute($request, $response) { if ($this->isInBackoffice()) { return website_BlockView::NONE; } $form = $this->getDocumentParameter(); if ($form === null || !$form->isPublished()) { return website_BlockView::NONE; } $request->setAttribute('form', $form); $request->setAttribute('moduleName', $this->getModuleName()); if ($request->hasParameter('receiverIds')) { $receiverIds = explode(',', $request->getParameter('receiverIds')); $receiverLabels = array(); foreach ($receiverIds as $receiverId) { if (is_numeric($receiverId)) { try { $receiver = DocumentHelper::getDocumentInstance($receiverId); $receiverLabels[] = $receiver->getLabel(); } catch (Exception $e) { Framework::exception($e); $receiverLabels[] = $receiverId; } } else { if (f_util_StringUtils::isNotEmpty($receiverId)) { $receiverLabels[] = $receiverId; } } } $request->setAttributes('receiverLabels', $receiverLabels); } $agaviUser = $this->getContext()->getGlobalContext()->getUser(); if ($agaviUser->hasAttribute('form_success_parameters_' . $form->getId())) { $view = $this->getSuccessView($form, $request); } else { if ($request->hasParameter('submit_' . $form->getId())) { try { $form->getDocumentService()->saveFormData($form, $request); $agaviUser->setAttribute('form_success_parameters_' . $form->getId(), $request->getParameters()); $view = $this->getSuccessView($form, $request); } catch (form_FormValidationException $e) { $request->setAttribute('errors', $e->getErrorCollection()); $view = $this->getInputView($form, $request); } } else { $view = $this->getInputView($form, $request); } } return $view; }
/** * @param form_persistentdocument_field $document * @param Integer $parentNodeId Parent node ID where to save the document (optionnal). * @return void */ protected function preSave($document, $parentNodeId = null) { $fieldName = $document->getFieldName(); if (f_util_StringUtils::isEmpty($fieldName)) { $this->fieldNameCounter = $this->fieldNameCounter + 1; $fieldName = 'f' . time() . $this->fieldNameCounter; if (Framework::isDebugEnabled()) { Framework::debug(__METHOD__ . ' Generate FieldName: ' . $fieldName . ' for document ' . $document->__toString()); } $document->setFieldName($fieldName); } $parentDoc = $parentNodeId != null ? DocumentHelper::getDocumentInstance($parentNodeId) : $this->getParentOf($document); form_BaseformService::getInstance()->checkFieldNameAvailable($document, $parentDoc->getId()); $this->fixRequiredConstraint($document); }
/** * @param String $code * @return boolean */ public static function checkCaptcha($code) { if (f_util_StringUtils::isNotEmpty($code)) { $sessionCode = Controller::getInstance()->getContext()->getUser()->getAttribute(CAPTCHA_SESSION_KEY); if ($sessionCode === $code) { Controller::getInstance()->getContext()->getUser()->setAttribute(CAPTCHA_SESSION_KEY, null); return true; } } return false; }
/** * @param block_BlockContext $context * @param block_BlockRequest $request * @return String the view name */ public function execute($context, $request) { $id = $this->getFormId(); if (empty($id)) { return block_BlockView::NONE; } $form = DocumentHelper::getDocumentInstance($id); if (!$form->isPublished()) { return block_BlockView::NONE; } $form->getDocumentNode()->getDescendents(); $this->setParameter('form', $form); if ($context->inBackofficeMode()) { return block_BlockView::DUMMY; } if ($request->hasParameter("receiverIds")) { $receiverIds = explode(",", $request->getParameter("receiverIds")); $receiverLabels = array(); foreach ($receiverIds as $receiverId) { if (is_numeric($receiverId)) { try { $receiver = DocumentHelper::getDocumentInstance($receiverId); $receiverLabels[] = $receiver->getLabel(); } catch (Exception $e) { Framework::exception($e); $receiverLabels[] = $receiverId; } } elseif (f_util_StringUtils::isNotEmpty($receiverId)) { $receiverLabels[] = $receiverId; } } $this->setParameter("receiverLabels", $receiverLabels); } if ($this->isSuccess($context, $request)) { $view = block_BlockView::SUCCESS; } else { if ($this->isFormPosted($request)) { $fs = form_FormService::getInstance(); try { $fs->saveFormData($form, $request); $user = $context->getGlobalContext()->getUser(); $user->setAttribute('form_success_parameters_' . $form->getId(), $request->getParameters()); $view = block_BlockView::SUCCESS; } catch (form_FormValidationException $e) { $this->setParameter('errors', $e->getErrorCollection()); $view = block_BlockView::INPUT; } } else { $view = block_BlockView::INPUT; } } // Calls the BlockFormDecorator if present. $formId = $form->getFormid(); $matches = null; if (preg_match('#^modules_([a-z]+)/([a-z]+)$#', $formId, $matches)) { $extendClassName = $matches[1] . '_BlockForm' . ucfirst($matches[2]) . 'Decorator'; if (f_util_ClassUtils::classExists($extendClassName)) { $instance = new $extendClassName($this); if ($instance instanceof form_BlockFormDecorator) { $instance->execute($context, $request); } else { Framework::warn("\"{$extendClassName}\" is not an instance of \"block_BlockDecorator\": form \"{$formId}\" won't be decorated."); } } } return $view; }