public function submit() { if ($this->validateAction()) { $post = $this->request->request->all(); $fsp = FilePermissions::getGlobal(); foreach ($post as $key => $value) { if (preg_match('/fsID:/', $key)) { $id = explode(':', $key); $fsID = $id[1]; $fs = Set::getByID($fsID); foreach ($this->files as $file) { if ($fsp->canAddFile($file)) { switch ($value) { case '0': if ($file->inFileSet($fs)) { $fs->removeFileFromSet($file); } break; case '1': // do nothing break; case '2': $fs->addFileToSet($file); break; } } } } } $fsNew = $this->request->request->get('fsNew'); $fsNewShare = $this->request->request->get('fsNewShare'); if (is_array($fsNew)) { foreach ($fsNew as $i => $name) { if ($name) { foreach ($this->files as $file) { $type = $fsNewShare[$i] == 1 ? Set::TYPE_PUBLIC : Set::TYPE_PRIVATE; $fs = Set::createAndGetSet($fsNew[$i], $type); $fs->addFileToSet($file); } } } } $sets = array(); foreach ($this->files as $file) { foreach ($file->getFileSets() as $set) { $o = $set->getJSONObject(); if (!in_array($o, $sets)) { $sets[] = $o; } } } $response = new EditResponse(); $response->setFiles($this->files); $response->setAdditionalDataAttribute('sets', $sets); $response->setMessage(t('File sets updated successfully.')); $response->outputJSON(); } }
/** * @param FileList $list * @param $request */ public function filterList(ItemList $list) { $ids = $this->data['fsID']; if (is_array($ids)) { foreach ($ids as $fsID) { $set = Set::getByID($fsID); if (is_object($set)) { $list->filterBySet($set); } } } }
public function action_submit($bID = null) { if ($this->bID == $bID) { $entityManager = \Core::make('database/orm')->entityManager(); $form = $this->getFormEntity(); if (is_object($form)) { $e = \Core::make('error'); $validator = new Validator($e, $this->request); $validator->validate($form); if ($this->displayCaptcha) { $captcha = \Core::make('helper/validation/captcha'); if (!$captcha->check()) { $e->add(t('Incorrect captcha code.')); } } $this->set('error', $e); } $entity = $form->getEntity(); $permissions = new \Permissions($entity); if (!$permissions->canAddExpressEntries()) { $e->add(t('You do not have access to submit this form.')); } if (isset($e) && !$e->has()) { $manager = new Manager($entityManager, $this->request); $entry = $manager->addEntry($entity); $entry = $manager->saveEntryAttributesForm($form, $entry); $values = $entity->getAttributeKeyCategory()->getAttributeValues($entry); // Check antispam $antispam = \Core::make('helper/validation/antispam'); $submittedData = ''; foreach ($values as $value) { $submittedData .= $value->getAttributeKey()->getAttributeKeyDisplayName() . ":\r\n"; $submittedData .= $value->getPlainTextValue() . "\r\n\r\n"; } if (!$antispam->check($submittedData, 'form_block')) { // Remove the entry and silently fail. $entityManager->refresh($entry); $entityManager->remove($entry); $entityManager->flush(); $c = \Page::getCurrentPage(); $r = Redirect::page($c); $r->setTargetUrl($r->getTargetUrl() . '#form' . $this->bID); return $r; } if ($this->addFilesToSet) { $set = Set::getByID($this->addFilesToSet); if (is_object($set)) { foreach ($values as $value) { $value = $value->getValueObject(); if ($value instanceof FileProviderInterface) { $files = $value->getFileObjects(); foreach ($files as $file) { $set->addFileToSet($file); } } } } } if ($this->notifyMeOnSubmission) { if (\Config::get('concrete.email.form_block.address') && strstr(\Config::get('concrete.email.form_block.address'), '@')) { $formFormEmailAddress = \Config::get('concrete.email.form_block.address'); } else { $adminUserInfo = \UserInfo::getByID(USER_SUPER_ID); $formFormEmailAddress = $adminUserInfo->getUserEmail(); } $replyToEmailAddress = $formFormEmailAddress; if ($this->replyToEmailControlID) { $control = $entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Control\\Control')->findOneById($this->replyToEmailControlID); if (is_object($control)) { $email = $entry->getAttribute($control->getAttributeKey()); if ($email) { $replyToEmailAddress = $email; } } } $formName = $this->getFormEntity()->getEntity()->getName(); $mh = \Core::make('helper/mail'); $mh->to($this->recipientEmail); $mh->from($formFormEmailAddress); $mh->replyto($replyToEmailAddress); $mh->addParameter('entity', $entity); $mh->addParameter('formName', $formName); $mh->addParameter('attributes', $values); $mh->load('block_express_form_submission'); $mh->setSubject(t('Website Form Submission – %s', $formName)); $mh->sendMail(); } if ($this->redirectCID > 0) { $c = \Page::getByID($this->redirectCID); if (is_object($c) && !$c->isError()) { $r = Redirect::page($c); $r->setTargetUrl($r->getTargetUrl() . '?form_success=1'); return $r; } } $c = \Page::getCurrentPage(); $url = \URL::to($c, 'form_success', $this->bID); $r = Redirect::to($url); $r->setTargetUrl($r->getTargetUrl() . '#form' . $this->bID); return $r; } } $this->view(); }