public function __construct($objModule) { $this->strPalette = $objModule->formHybridPalette; $this->strMethod = FORMHYBRID_METHOD_GET; $this->isFilterForm = true; parent::__construct($objModule); }
public function __construct($objConfig, array $submitCallbacks = array(), $intId = 0, $objReaderForm) { $this->strMethod = FORMHYBRID_METHOD_POST; $objConfig->strTemplate = $objConfig->strTemplate ?: 'formhybrid_default'; $this->objReaderModule = $objReaderForm; if ($objConfig->addClientsideValidation) { $objConfig->strFormClass = 'jquery-validation'; } $this->arrSubmitCallbacks = $submitCallbacks; parent::__construct($objConfig, $intId); }
public function __construct($objModule) { $this->strMethod = FORMHYBRID_METHOD_GET; $this->isFilterForm = true; $this->objListModule = $objModule; $objModule->formHybridTemplate = $objModule->formHybridTemplate ?: 'formhybrid_list_filter'; $objModule->formHybridEditable = $objModule->customFilterFields; $objModule->formHybridCustomSubmit = true; $objModule->formHybridSubmitLabel = 'filter'; $arrHeadline = deserialize($objModule->filterHeadline); $objModule->filterHeadline = is_array($arrHeadline) ? $arrHeadline['value'] : $arrHeadline; $objModule->filterHl = is_array($arrHeadline) ? $arrHeadline['unit'] : 'h1'; $objModule->formHybridSkipValidation = true; parent::__construct($objModule); }
protected function processForm() { // get a product collection (aka cart) global $objPage; $objCart = new Cart(); // Can't call the individual rows here, it would trigger markModified and a save() $objCart->setRow(array_merge($objCart->row(), array('tstamp' => time(), 'member' => 0, 'uniqid' => null, 'config_id' => $this->iso_config_id, 'store_id' => (int) \PageModel::findByPk($objPage->rootId)->iso_store_id))); $objSubmission = $this->getSubmission(false); // add products to cart foreach ($this->arrProducts as $arrProduct) { $strProduct = 'product_' . $arrProduct['product']->id; $strQuantity = 'quantity_' . $arrProduct['product']->id; if (($this->getProductCount() > 1 || $this->getTypeCount() > 1) && !$objSubmission->{$strProduct}) { continue; } if (!$objCart->addProduct($arrProduct['product'], $arrProduct['useQuantity'] ? $objSubmission->{$strQuantity} : 1)) { $this->transformIsotopeErrorMessages(); return; } } $objCart->save(); $objOrder = $objCart->getDraftOrder(); // temporarily override the cart for generating the reviews... $objCartTmp = Isotope::getCart(); Isotope::setCart($objCart); // create steps $arrSteps = array(); $arrCheckoutInfo = array(); // billing address $objBillingAddress = new Address(); foreach ($this->arrBillingAddressFields as $strName) { $objBillingAddress->{$strName} = $objSubmission->{$strName}; } $objBillingAddress->save(); $objOrder->setBillingAddress($objBillingAddress); $objBillingAddressStep = new BillingAddress($this->objCheckoutModule); $arrSteps[] = $objBillingAddressStep; $arrCheckoutInfo['billing_address'] = $objBillingAddressStep->review()['billing_address']; // shipping address $objShippingAddress = new Address(); // standard isotope handling for distinguishing between the address types: // -> if only a billing address is available, it's also the shipping address foreach ($objSubmission->shippingaddress ? $this->arrShippingAddressFields : $this->arrBillingAddressFields as $strName) { $objShippingAddress->{str_replace('shippingaddress_', '', $strName)} = $objSubmission->{$objSubmission->shippingaddress ? $strName : str_replace('shippingaddress_', 'billingaddress_', $strName)}; } $objShippingAddress->save(); // $objOrder->setShippingAddress($objShippingAddress); // $objShippingAddressStep = new ShippingAddress($this->objCheckoutModule); // $arrSteps[] = $objShippingAddressStep; // $arrCheckoutInfo['shipping_address'] = $objShippingAddressStep->review()['shipping_address']; // add shipping method $objIsotopeShipping = Flat::findByPk($this->iso_shipping_modules); $objOrder->setShippingMethod($objIsotopeShipping); $objShippingMethodStep = new ShippingMethod($this->objCheckoutModule); $arrSteps[] = $objShippingMethodStep; $arrCheckoutInfo['shipping_method'] = $objShippingMethodStep->review()['shipping_method']; // add all the checkout info to the order $objOrder->checkout_info = $arrCheckoutInfo; $objOrder->notes = $objSubmission->notes; //... restore the former cart again Isotope::setCart($objCartTmp); $objOrder->nc_notification = $this->nc_notification; $objOrder->email_data = $this->getNotificationTokensFromSteps($arrSteps, $objOrder); // !HOOK: pre-process checkout if (isset($GLOBALS['ISO_HOOKS']['preCheckout']) && is_array($GLOBALS['ISO_HOOKS']['preCheckout'])) { foreach ($GLOBALS['ISO_HOOKS']['preCheckout'] as $callback) { $objCallback = \System::importStatic($callback[0]); if ($objCallback->{$callback}[1]($objOrder, $this->objCheckoutModule) === false) { \System::log('Callback ' . $callback[0] . '::' . $callback[1] . '() cancelled checkout for Order ID ' . $this->id, __METHOD__, TL_ERROR); $this->objCheckoutModule->redirectToStep('failed'); } } } $objOrder->lock(); $objOrder->checkout(); $objOrder->complete(); if (is_array($this->dca['config']['onsubmit_callback'])) { foreach ($this->dca['config']['onsubmit_callback'] as $key => $callback) { if ($callback[0] == 'Isotope\\Backend\\ProductCollection\\Callback' && $callback[1] == 'executeSaveHook') { unset($this->dca['config']['onsubmit_callback'][$key]); break; } } } $this->transformIsotopeErrorMessages(); parent::processForm(); }
protected function prepareSubmissionData() { $arrSubmissionData = parent::prepareSubmissionData(); $arrSubmissionData['domain'] = \Idna::decode(\Environment::get('host')); $arrSubmissionData['activation'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $this->activeRecord->activation; if (in_array('newsletter', \ModuleLoader::getActive())) { // Replace the wildcard if (!empty($this->objModel->newsletter)) { $objChannels = \NewsletterChannelModel::findByIds($this->activeRecord->newsletter); if ($objChannels !== null) { $arrSubmissionData['channels'] = implode("\n", $objChannels->fetchEach('title')); } } } // Backwards compatibility $arrSubmissionData['channel'] = $arrSubmissionData['channels']; return $arrSubmissionData; }
protected function compile() { $this->Template->headline = $this->headline; $this->Template->hl = $this->hl; $this->Template->wrapperClass = $this->strWrapperClass; $this->Template->wrapperId = $this->strWrapperId; $this->strFormId = $this->formHybridDataContainer . '_' . $this->id; $strAction = $this->defaultAction ?: \Input::get('act'); $this->arrEditable = deserialize($this->formHybridEditable, true); $this->strToken = $this->strToken ?: \Input::get('token'); // Do not change this order (see #6191) $this->Template->style = !empty($this->arrStyle) ? implode(' ', $this->arrStyle) : ''; $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]); $this->Template->cssID = $this->cssID[0] != '' ? ' id="' . $this->cssID[0] . '"' : ''; $this->Template->inColumn = $this->strColumn; if ($this->Template->headline == '') { $this->Template->headline = $this->headline; } if ($this->Template->hl == '') { $this->Template->hl = $this->hl; } if (!empty($this->classes) && is_array($this->classes)) { $this->Template->class .= ' ' . implode(' ', $this->classes); } $this->addDefaultArchive(); // at first check for the correct request token to be set if (!$this->deactivateTokens && !\RequestToken::validate($this->strToken)) { if (!$this->blnSilentMode) { StatusMessage::addError(sprintf($GLOBALS['TL_LANG']['frontendedit']['requestTokenExpired'], Url::replaceParameterInUri(Url::getUrl(), 'token', \RequestToken::get())), $this->id, 'requestTokenExpired'); } return; } if ($this->formHybridAllowIdAsGetParameter) { $intId = \Input::get($this->formHybridIdGetParameter); if (is_numeric($intId)) { $this->intId = $intId; } } $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer); // get id from share if ($strShare = \Input::get('share')) { if (($objItem = $strItemClass::findByShareToken($strShare)) !== null && !FormHybridList::shareTokenExpiredOrEmpty($objItem, time())) { $this->intId = $objItem->id; } } if (!$this->intId) { if (isset($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior']) && is_array($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'])) { foreach ($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'] as $arrCallback) { $this->import($arrCallback[0]); if ($this->{$arrCallback}[0]->{$arrCallback}[1]($this) === false) { return; } } } if ($this->noIdBehavior == 'error') { if (!$this->blnSilentMode) { StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound'); } return; } elseif ($this->noIdBehavior == 'redirect' || $this->noIdBehavior == 'create_until') { $arrConditions = deserialize($this->existanceConditions, true); if ($this->existanceConditions && !empty($arrConditions)) { $arrColumns = array(); $arrValues = array(); foreach ($arrConditions as $arrCondition) { if (!$arrCondition['field']) { continue; } $arrColumns[] = $arrCondition['field'] . '=?'; $arrValues[] = $this->replaceInsertTags($arrCondition['value']); } if (!empty($arrColumns) && ($objItem = $strItemClass::findOneBy($arrColumns, $arrValues)) !== null) { $this->intId = $objItem->id; } } } if (!$this->intId) { if ($this->noIdBehavior == 'redirect') { if (!$this->blnSilentMode) { StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound'); } return; } else { $strFormId = FormHelper::getFormId($this->formHybridDataContainer, $this->id); // get id from FormSession if ($_POST) { if ($intId = FormSession::getSubmissionId($strFormId)) { $this->intId = $intId; } } if (!$this->intId) { // if no id is given a new instance is initiated $objConfiguration = new FormConfiguration($this->arrData); // ajax handling, required in this manor, as we have no real ajax controller in contao and ajax request not related to this module // might trigger this module beforhand and new submission will be created after the submission was transfered to the user and id wont match any more if (Ajax::isRelated(Form::FORMHYBRID_NAME) !== null) { if ($intId = FormSession::getSubmissionId($strFormId)) { $this->intId = $intId; } else { $objConfiguration->forceCreate = true; } } $this->objForm = new $this->strFormClass($objConfiguration, $this->arrSubmitCallbacks, $this->intId ?: 0, $this); if ($intId = $this->objForm->getId()) { $this->intId = $intId; } } } } } // intId is set at this point! if (!$this->checkEntityExists($this->intId)) { if (!$this->blnSilentMode) { StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission'); } if (Ajax::isRelated(Form::FORMHYBRID_NAME)) { $objResponse = new ResponseError(); $objResponse->setResult(StatusMessage::generate($this->id)); $objResponse->output(); } return; } // page title if ($this->setPageTitle) { global $objPage; if (($objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId)) !== null) { $objPage->pageTitle = $objItem->{$this->pageTitleField}; } } if ($strAction == FRONTENDEDIT_ACT_DELETE) { if ($this->checkDeletePermission($this->intId)) { $blnResult = $this->deleteItem($this->intId); if (\Environment::get('isAjaxRequest')) { die($blnResult); } // return to the list \Controller::redirect(Url::removeQueryString(array('act', 'id', 'token'), Url::getUrl())); } else { if (!$this->blnSilentMode) { StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission'); } return; } } else { if ($this->checkUpdatePermission($this->intId)) { // create a new lock if necessary if (in_array('entity_lock', \ModuleLoader::getActive()) && $this->addEntityLock) { if (\HeimrichHannot\EntityLock\EntityLockModel::isLocked($this->formHybridDataContainer, $this->intId, $this)) { $objLock = \HeimrichHannot\EntityLock\EntityLockModel::findActiveLock($this->formHybridDataContainer, $this->intId, $this); $objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId); if (!$this->blnSilentMode) { $strMessage = \HeimrichHannot\EntityLock\EntityLock::generateErrorMessage($this->formHybridDataContainer, $this->intId, $this); if ($this->allowLockDeletion) { $strUnlockForm = $this->generateUnlockForm($objItem, $objLock); $strMessage .= $strUnlockForm; } StatusMessage::addError($strMessage, $this->id, 'locked'); } if ($this->readOnlyOnLocked) { $this->formHybridViewMode = FORMHYBRID_VIEW_MODE_READONLY; $this->formHybridReadonlyTemplate = 'formhybridreadonly_default'; } else { return; } } else { \HeimrichHannot\EntityLock\EntityLockModel::create($this->formHybridDataContainer, $this->intId, $this); } } if ($this->objForm === null) { $this->objForm = new $this->strFormClass(new FormConfiguration($this->arrData), $this->arrSubmitCallbacks, $this->intId, $this); } $this->Template->form = $this->objForm->generate(); $this->Template->item = $this->objForm->activeRecord; if (\Environment::get('isAjaxRequest') && \Input::get('scope') == 'modal') { $objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId); $objModalWrapper = new \FrontendTemplate($this->modalTpl ?: 'formhybrid_reader_modal_bootstrap'); if ($objItem !== null) { $objModalWrapper->setData($objItem->row()); } $objModalWrapper->module = Arrays::arrayToObject($this->arrData); $objModalWrapper->item = $this->replaceInsertTags($this->Template->parse()); die($objModalWrapper->parse()); } } else { if (!$this->blnSilentMode) { StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission'); } return; } } }