Ejemplo n.º 1
0
 public static function getFileSetFiles(Set $fs)
 {
     $db = Loader::db();
     $r = $db->query('SELECT fsfID FROM FileSetFiles WHERE fsID = ? ORDER BY fsDisplayOrder ASC', array($fs->getFileSetID()));
     $files = array();
     while ($row = $r->FetchRow()) {
         $fsf = static::getByID($row['fsfID']);
         if (is_object($fsf)) {
             $files[] = $fsf;
         }
     }
     return $files;
 }
Ejemplo n.º 2
0
 public static function add($name, $searchRequest, $searchColumnsObject)
 {
     $fs = parent::createAndGetSet($name, FileSet::TYPE_SAVED_SEARCH);
     $db = Loader::db();
     $v = array($fs->getFileSetID(), serialize($searchRequest), serialize($searchColumnsObject));
     $db->Execute('INSERT INTO FileSetSavedSearches (fsID, fsSearchRequest, fsResultColumns) VALUES (?, ?, ?)', $v);
     return $fs;
 }
Ejemplo n.º 3
0
 public function submit()
 {
     if ($this->validateAction()) {
         $post = $this->request->request->all();
         foreach ($post as $key => $value) {
             if (preg_match('/fsID:/', $key)) {
                 $id = explode(':', $key);
                 $fsID = $id[1];
                 $fs = Set::getByID($fsID);
                 $fsp = new \Permissions($fs);
                 foreach ($this->files as $file) {
                     if ($fsp->canAddFile($file)) {
                         switch ($value) {
                             case '0':
                                 $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();
     }
 }
Ejemplo n.º 4
0
 public function setPermissionObject(Set $fs)
 {
     $this->permissionObject = $fs;
     if ($fs->overrideGlobalPermissions()) {
         $this->permissionObjectToCheck = $fs;
     } else {
         $fs = Set::getGlobal();
         $this->permissionObjectToCheck = $fs;
     }
 }
Ejemplo n.º 5
0
 public function renderSearchField()
 {
     $form = \Core::make('helper/form');
     $sets = array();
     $u = new \User();
     $fileSets = Set::getMySets($u);
     foreach ($fileSets as $set) {
         $sets[$set->getFileSetID()] = $set->getFileSetName();
     }
     return $form->selectMultiple('fsID', $sets, $this->data['fsID'], ['class' => 'selectize-select']);
 }
Ejemplo n.º 6
0
 public function submit()
 {
     $requestSets = array();
     if (is_array($this->request->request->get('fsID'))) {
         $requestSets = $this->request->request->get('fsID');
     }
     if ($this->validateAction()) {
         $sets = Set::getMySets();
         foreach ($sets as $set) {
             $fsp = new \Permissions($set);
             if (in_array($set->getFileSetID(), $requestSets) && $fsp->canAddFile($this->file) && !$this->file->inFileSet($set)) {
                 // This was checked and it wasn't in the file set previously
                 $set->addFileToSet($this->file);
             }
             if ($this->file->inFileSet($set) && !in_array($set->getFileSetID(), $requestSets) && $fsp->canAddFile($this->file)) {
                 // This was not checked but it used to be in the set.
                 $set->removeFileFromSet($this->file);
             }
         }
     }
     $fsNew = $this->request->request->get('fsNew');
     $fsNewShare = $this->request->request->get('fsNewShare');
     if (is_array($fsNew)) {
         foreach ($fsNew as $i => $name) {
             if ($name) {
                 $type = $fsNewShare[$i] == 1 ? Set::TYPE_PUBLIC : Set::TYPE_PRIVATE;
                 $fs = Set::createAndGetSet($fsNew[$i], $type);
                 $fs->addFileToSet($this->file);
             }
         }
     }
     $response = new EditResponse();
     $response->setFile($this->file);
     $response->setMessage(t('File sets updated successfully.'));
     $response->outputJSON();
 }
Ejemplo n.º 7
0
 public function attachFile(File $f)
 {
     $db = Loader::db();
     if (!is_object($f)) {
         return false;
     } else {
         $db->Execute('INSERT INTO ConversationMessageAttachments (cnvMessageID, fID) VALUES (?, ?)', array($this->getConversationMessageID(), $f->getFileID()));
         $fs = FileSet::createAndGetSet(Config::get('conversations.attachments_file_set'), FileSet::TYPE_PUBLIC, USER_SUPER_ID);
         $fsToRemove = FileSet::createAndGetSet(Config::get('conversations.attachments_pending_file_set'), FileSet::TYPE_PUBLIC, USER_SUPER_ID);
         $fs->addFileToSet($f);
         $fsToRemove->removeFileFromSet($f);
     }
     // associate with non-pending file set.
 }
Ejemplo n.º 8
0
 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();
 }
Ejemplo n.º 9
0
 public function getFileSet()
 {
     $fs = Set::getByName($this->getID());
     return $fs;
 }
Ejemplo n.º 10
0
 public function upload_files()
 {
     $files = array();
     if ($this->token->validate('upload_files')) {
         $r = $this->entityManager->getRepository('\\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Import\\Batch');
         $batch = $r->findOneById($this->request->request('id'));
         if (is_object($batch)) {
             $cf = \Core::make('helper/file');
             $fp = \FilePermissions::getGlobal();
             if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
                 if (!$fp->canAddFileType($cf->getExtension($_FILES['file']['name']))) {
                     throw new \Exception(Importer::getErrorMessage(Importer::E_FILE_INVALID_EXTENSION));
                 } else {
                     $ih = new Importer();
                     $response = $ih->import($_FILES['file']['tmp_name'], $_FILES['file']['name']);
                     if (!$response instanceof \Concrete\Core\File\Version) {
                         throw new \Exception(Importer::getErrorMessage($response));
                     } else {
                         $file = $response->getFile();
                         $fs = Set::getByName($batch->getID());
                         if (!is_object($fs)) {
                             $fs = Set::createAndGetSet($batch->getID(), Set::TYPE_PRIVATE);
                         }
                         $fs->addFileToSet($file);
                         $files[] = $file;
                     }
                 }
             }
         }
     }
     $this->flash('success', t('File(s) uploaded successfully'));
     $r = new \Concrete\Core\File\EditResponse();
     $r->setFiles($files);
     $r->outputJSON();
 }
Ejemplo n.º 11
0
 public function getJSONObject()
 {
     return parent::getJSONObject();
 }