Пример #1
2
    protected function populateFiles()
    {
        if (is_array($_REQUEST['fID'])) {
            foreach ($_REQUEST['fID'] as $fID) {
                $f = File::getByID($fID);
                if (is_object($f)) {
                    $this->files[] = $f;
                }
            }
        }

        if (count($this->files) > 0) {
            $this->canEdit = true;
            foreach ($this->files as $f) {
                $fp = new \Permissions($f);
                if (!$fp->canViewFileInFileManager()) {
                    $this->canEdit = false;
                }
            }
        } else {
            $this->canEdit = false;
        }

        return $this->canEdit;
    }
Пример #2
2
 public function getContentObject()
 {
     $db = \Database::connection();
     $fID = $db->GetOne('select fID from FileVersions where fvFilename = ?', array($this->getReference()));
     if ($fID) {
         $f = File::getByID($fID);
         return $f;
     }
 }
Пример #3
1
 /**
  * @param $queryRow
  * @return \Concrete\Core\File\File
  */
 public function getResult($queryRow)
 {
     $f = File::getByID($queryRow['fID']);
     if (is_object($f) && $this->checkPermissions($f)) {
         return $f;
     }
 }
Пример #4
1
 public function getTreeNodeName()
 {
     $f = \Concrete\Core\File\File::getByID($this->fID);
     if (is_object($f)) {
         return $f->getFileName();
     }
 }
Пример #5
1
 public static function createAndGetFile($f_id, $fs_id)
 {
     $db = Loader::db();
     $fsfID = $db->GetOne('SELECT fsfID FROM FileSetFiles WHERE fID = ? AND fsID = ?', array($f_id, $fs_id));
     if ($fsfID > 0) {
         return static::getByID($fsfID);
     } else {
         $fs = FileSet::getByID($fs_id);
         $f = \Concrete\Core\File\File::getByID($f_id);
         $fsf = static::add($f, $fs);
         return $fsf;
     }
 }
Пример #6
1
 public function on_start()
 {
     if (!isset($this->file)) {
         $request = $this->request;
         $fID = Loader::helper('security')->sanitizeInt($request->query->get('fID'));
         if ($fID) {
             $file = ConcreteFile::getByID($fID);
             if (is_object($file) && !$file->isError()) {
                 $this->setFileObject($file);
             } else {
                 throw new Exception(t('Invalid file.'));
             }
         }
     }
 }
Пример #7
0
 public function submit()
 {
     if ($this->validateAction()) {
         $post = $this->request->request->all();
         $fsl = FileStorageLocation::getByID($post['fslID']);
         if (is_object($fsl)) {
             $fIDs = $post['fID'];
             if (is_array($fIDs)) {
                 foreach ($fIDs as $fID) {
                     $f = File::getByID($fID);
                     if (is_object($f)) {
                         $fp = new Permissions($f);
                         if ($fp->canEditFilePermissions()) {
                             try {
                                 $f->setFileStorageLocation($fsl);
                             } catch (\Exception $e) {
                                 $json = new \Concrete\Core\Application\EditResponse();
                                 $err = \Core::make('error');
                                 $err->add($e->getMessage());
                                 $json->setError($err);
                                 $json->outputJSON();
                             }
                         }
                     }
                 }
             }
         } else {
             $json = new \Concrete\Core\Application\EditResponse();
             $err = \Core::make('error');
             $err->add(t('Please select valid file storage location.'));
             $json->setError($err);
             $json->outputJSON();
         }
         $response = new EditResponse();
         $response->setFiles($this->files);
         $response->setMessage(t('File storage locations updated successfully.'));
         $response->outputJSON();
     }
 }
Пример #8
0
 /**
  * @return \Concrete\Core\Entity\File\File|null
  */
 public function getFileObject()
 {
     return File::getByID($this->getFileID());
 }
Пример #9
0
 public function rescanMultiple()
 {
     $files = $this->getRequestFiles('canEditFileContents');
     $q = Queue::get('rescan_files');
     if ($_POST['process']) {
         $obj = new stdClass();
         $messages = $q->receive(5);
         foreach ($messages as $key => $msg) {
             // delete the page here
             $file = unserialize($msg->body);
             $f = \Concrete\Core\File\File::getByID($file['fID']);
             if (is_object($f)) {
                 $this->doRescan($f);
             }
             $q->deleteMessage($msg);
         }
         $obj->totalItems = $q->count();
         if ($q->count() == 0) {
             $q->deleteQueue(5);
         }
         print json_encode($obj);
         exit;
     } else {
         if ($q->count() == 0) {
             foreach ($files as $f) {
                 $q->send(serialize(array('fID' => $f->getFileID())));
             }
         }
     }
     $totalItems = $q->count();
     Loader::element('progress_bar', array('totalItems' => $totalItems, 'totalItemsSummary' => t2("%d file", "%d files", $totalItems)));
     return;
 }
Пример #10
0
 public function action_delete_case_document($bID = false, $DocumentID)
 {
     if ($this->bID != $bID) {
         return false;
     }
     $this->view();
     $user = new User();
     $file = \Concrete\Core\File\File::getByID($DocumentID);
     if ($file->getUserID() != $user->getUserID()) {
         return;
     }
     $file->delete();
     $db = Loader::db();
     $ql = "DELETE FROM `CaseDocuments` WHERE DocumentID=? AND DocumentOwnerID=?";
     $val = array(intval($DocumentID), intval($user->getUserID()));
     $db->query($ql, $val);
 }
Пример #11
0
 public function csv()
 {
     $dateHelper = Loader::helper('date');
     /* @var $dateHelper \Concrete\Core\Localization\Service\Date */
     $this->pageSize = 0;
     $this->loadSurveyResponses();
     $textHelper = Loader::helper('text');
     $questionSet = $this->get('questionSet');
     $answerSets = $this->get('answerSets');
     $questions = $this->get('questions');
     $surveys = $this->get('surveys');
     $escapeCharacter = "'";
     $charactersToEscape = array('-', '+', '=');
     $fileName = $textHelper->filterNonAlphaNum($surveys[$questionSet]['surveyName']);
     header("Content-Type: text/csv");
     header("Cache-control: private");
     header("Pragma: public");
     $date = date('Ymd');
     header("Content-Disposition: attachment; filename=" . $fileName . "_form_data_{$date}.csv");
     $fp = fopen('php://output', 'w');
     // write the columns
     $row = array(t('Submitted Date'), t('User'));
     foreach ($questions as $questionId => $question) {
         if ($question['inputType'] == 'checkboxlist') {
             $options = explode('%%', $question['options']);
             foreach ($options as $opt) {
                 $row[] = $questions[$questionId]['question'] . ': ' . $opt;
             }
         } else {
             $row[] = $questions[$questionId]['question'];
         }
     }
     fputcsv($fp, $row);
     // write the data
     foreach ($answerSets as $answerSet) {
         $row = array();
         $row[] = $dateHelper->formatCustom($dateHelper::DB_FORMAT, $answerSet['created']);
         if ($answerSet['uID'] > 0) {
             $ui = UserInfo::getByID($answerSet['uID']);
             if (is_object($ui)) {
                 $row[] = $ui->getUserName();
             }
         } else {
             $row[] = '';
         }
         foreach ($questions as $questionId => $question) {
             if ($question['inputType'] == 'checkboxlist') {
                 $options = explode('%%', $question['options']);
                 $subanswers = explode(',', $answerSet['answers'][$questionId]['answer']);
                 for ($i = 1; $i <= count($options); $i++) {
                     if (in_array(trim($options[$i - 1]), $subanswers)) {
                         $row[] = 'x';
                     } else {
                         $row[] = '';
                     }
                 }
             } else {
                 if ($question['inputType'] == 'fileupload') {
                     $fID = intval($answerSet['answers'][$questionId]['answer']);
                     $file = File::getByID($fID);
                     if ($fID && $file) {
                         $fileVersion = $file->getApprovedVersion();
                         $row[] = $fileVersion->getDownloadURL();
                     } else {
                         $row[] = t('File not found');
                     }
                 } else {
                     $answer = $answerSet['answers'][$questionId]['answer'] . $answerSet['answers'][$questionId]['answerLong'];
                     if (in_array(substr($answer, 0, 1), $charactersToEscape)) {
                         $row[] = $escapeCharacter . $answer;
                     } else {
                         $row[] = $answer;
                     }
                 }
             }
         }
         fputcsv($fp, $row);
     }
     fclose($fp);
     die;
 }
Пример #12
0
 /**
  * Called when we're saving the attribute from the frontend.
  * @param $data
  */
 public function saveForm($data)
 {
     $sessionKey = $data['value'];
     $files = $_SESSION['multi_file'][$sessionKey];
     $db = Database::connection();
     // create or get file set
     $fileSetName = sprintf('Multi File %s', date('Y-m-d'));
     $fileSet = FileSet::getByID($data['fsID']);
     if ($fileSet == null) {
         $fileSet = FileSet::add($fileSetName);
     }
     $db->Replace('atMultiFile', array('avID' => $this->getAttributeValueID(), 'fsID' => $fileSet->getFileSetID()), 'avID', true);
     // Update sort order of files
     if (isset($data['sortOrder']) && !empty($data['sortOrder'])) {
         $sortOrder = $data['sortOrder'];
         parse_str($sortOrder, $sortOrderArray);
         $fileSet->updateFileSetDisplayOrder($sortOrderArray['file']);
     }
     // Remove files
     if (isset($data['removeFiles']) && !empty($data['removeFiles'])) {
         $removeFiles = preg_split('[,]', $data['removeFiles'], -1, PREG_SPLIT_NO_EMPTY);
         foreach ($removeFiles as $fID) {
             $file = File::getByID($fID);
             if (!is_null($file)) {
                 $file->delete();
             }
         }
     }
     // Import files
     if (is_array($files)) {
         foreach ($files as $file) {
             $fi = new FileImporter();
             $fileVersion = $fi->import($file['fileName'], $file['name']);
             unlink($file['fileName']);
             if ($fileVersion instanceof Version) {
                 $fileSet->addFileToSet($fileVersion);
             } else {
                 // @TODO now what?
                 switch ($fileVersion) {
                     case FileImporter::E_FILE_INVALID_EXTENSION:
                         break;
                     case FileImporter::E_FILE_INVALID:
                         break;
                 }
             }
         }
     }
     // Clear session
     unset($_SESSION['multi_file'][$sessionKey]);
 }
Пример #13
0
 /**
  * @param int $fID File ID
  */
 public function submit_password($fID = 0)
 {
     if ($fID > 0 && $this->app->make('helper/validation/numbers')->integer($fID)) {
         $f = File::getByID($fID);
         $rcID = $this->post('rcID');
         $rcID = $this->app->make('helper/security')->sanitizeInt($rcID);
         if ($f->getPassword() == $this->post('password')) {
             if ($this->post('force')) {
                 return $this->force_download($f);
             } else {
                 return $this->download($f);
             }
         }
         $this->set('error', t("Password incorrect. Please try again."));
         $this->set('force', $this->post('force') ? 1 : 0);
         $this->view($fID, $rcID);
     }
 }
Пример #14
0
 /**
  * @return
  */
 public function getVersion()
 {
     return File::getByID($this->fID, $this->fvID);
 }
 public function csv()
 {
     $dateHelper = Core::make('helper/date');
     /* @var $dateHelper \Concrete\Core\Localization\Service\Date */
     $this->pageSize = 0;
     $this->loadSurveyResponses();
     $textHelper = Core::make('helper/text');
     $questionSet = $this->get('questionSet');
     $answerSets = $this->get('answerSets');
     $questions = $this->get('questions');
     $surveys = $this->get('surveys');
     $fileName = $textHelper->filterNonAlphaNum($surveys[$questionSet]['surveyName']);
     if (!empty($_REQUEST['encoding'])) {
         $encoding = $textHelper->filterNonAlphaNum($_REQUEST['encoding']);
     }
     header("Content-Type: text/csv");
     header("Cache-control: private");
     header("Pragma: public");
     $date = date('Ymd');
     header("Content-Disposition: attachment; filename=" . $fileName . "_form_data_{$date}.csv");
     // write the columns
     if ($encoding && function_exists(mb_convert_encoding)) {
         $fp = fopen('php://temp', 'w');
         $row = array(mb_convert_encoding(t('Submitted Date'), $encoding), mb_convert_encoding(t('User'), $encoding));
         foreach ($questions as $questionId => $question) {
             if ($question['inputType'] == 'checkboxlist') {
                 $options = explode('%%', $question['options']);
                 foreach ($options as $opt) {
                     $row[] = mb_convert_encoding($questions[$questionId]['question'], $encoding) . ': ' . mb_convert_encoding($opt, $encoding);
                 }
             } else {
                 $row[] = mb_convert_encoding($questions[$questionId]['question'], $encoding);
             }
         }
         fputcsv($fp, $row);
         // write the data
         foreach ($answerSets as $answerSet) {
             $row = array();
             $row[] = $dateHelper->formatCustom($dateHelper::DB_FORMAT, $answerSet['created']);
             if ($answerSet['uID'] > 0) {
                 $ui = UserInfo::getByID($answerSet['uID']);
                 if (is_object($ui)) {
                     $row[] = $ui->getUserName();
                 }
             } else {
                 $row[] = '';
             }
             foreach ($questions as $questionId => $question) {
                 if ($question['inputType'] == 'checkboxlist') {
                     $options = explode('%%', mb_convert_encoding($question['options'], $encoding));
                     $subanswers = explode(',', mb_convert_encoding($answerSet['answers'][$questionId]['answer'], $encoding));
                     for ($i = 1; $i <= count($options); $i++) {
                         if (in_array(trim($options[$i - 1]), $subanswers)) {
                             $row[] = 'x';
                         } else {
                             $row[] = '';
                         }
                     }
                 } else {
                     if ($question['inputType'] == 'fileupload') {
                         $fID = intval($answerSet['answers'][$questionId]['answer']);
                         $file = File::getByID($fID);
                         if ($fID && $file) {
                             $fileVersion = $file->getApprovedVersion();
                             $row[] = $fileVersion->getDownloadURL();
                         } else {
                             $row[] = t('File not found');
                         }
                     } else {
                         $row[] = mb_convert_encoding($answerSet['answers'][$questionId]['answer'], $encoding) . mb_convert_encoding($answerSet['answers'][$questionId]['answerLong'], $encoding);
                     }
                 }
             }
         }
         fputcsv($fp, $row);
         rewind($fp);
         if ($encoding == "SJIS") {
             $csvContents = str_replace("\n", "\r\n", stream_get_contents($fp));
         } else {
             $csvContents = $fp;
         }
         fclose($fp);
         $fpmain = fopen('php://output', 'w');
         fwrite($fpmain, $csvContents);
         fclose($fpmain);
         die;
     } else {
         $fp = fopen('php://output', 'w');
         $row = array(t('Submitted Date'), t('User'));
         foreach ($questions as $questionId => $question) {
             if ($question['inputType'] == 'checkboxlist') {
                 $options = explode('%%', $question['options']);
                 foreach ($options as $opt) {
                     $row[] = $questions[$questionId]['question'] . ': ' . $opt;
                 }
             } else {
                 $row[] = $questions[$questionId]['question'];
             }
         }
         fputcsv($fp, $row);
         // write the data
         foreach ($answerSets as $answerSet) {
             $row = array();
             $row[] = $dateHelper->formatCustom($dateHelper::DB_FORMAT, $answerSet['created']);
             if ($answerSet['uID'] > 0) {
                 $ui = UserInfo::getByID($answerSet['uID']);
                 if (is_object($ui)) {
                     $row[] = $ui->getUserName();
                 }
             } else {
                 $row[] = '';
             }
             foreach ($questions as $questionId => $question) {
                 if ($question['inputType'] == 'checkboxlist') {
                     $options = explode('%%', $question['options']);
                     $subanswers = explode(',', $answerSet['answers'][$questionId]['answer']);
                     for ($i = 1; $i <= count($options); $i++) {
                         if (in_array(trim($options[$i - 1]), $subanswers)) {
                             $row[] = 'x';
                         } else {
                             $row[] = '';
                         }
                     }
                 } else {
                     if ($question['inputType'] == 'fileupload') {
                         $fID = intval($answerSet['answers'][$questionId]['answer']);
                         $file = File::getByID($fID);
                         if ($fID && $file) {
                             $fileVersion = $file->getApprovedVersion();
                             $row[] = $fileVersion->getDownloadURL();
                         } else {
                             $row[] = t('File not found');
                         }
                     } else {
                         $row[] = $answerSet['answers'][$questionId]['answer'] . $answerSet['answers'][$questionId]['answerLong'];
                     }
                 }
             }
         }
         fputcsv($fp, $row);
         fclose($fp);
         die;
     }
 }
Пример #16
-1
 public function view($object, $mode = 'select')
 {
     $this->set('object', $object);
     $migrate = new Migration();
     // process import file selection
     if ($mode == 'select' && $this->post()) {
         $data = $this->post();
         $file_id = $data['file'];
         if ($file_id) {
             $file = File::getByID($file_id);
             $file_version = $file->getRecentVersion();
             if ($object == 'file') {
                 $filePath = $file_version->getRelativePath();
                 $fi = new FileImport();
                 $test = $fi->importTest();
                 $mode = 'test';
                 $this->set('test', $test);
             } else {
                 $file_contents = $file_version->getFileContents();
                 $this->xml = simplexml_load_string($file_contents);
                 $mode = 'test';
                 $migrate->importTest($object, $this->xml);
                 $this->set('test', $migrate->test);
             }
             $this->set('file_id', $file_id);
         }
     }
     // do migration
     if ($mode == 'execute' && $this->post()) {
         $data = $this->post();
         $file_id = $data['file'];
         $file = File::getByID($file_id);
         $file_version = $file->getRecentVersion();
         if ($object == 'file') {
             $fi = new FileImport();
             $result = $fi->import($file_version);
             $this->set('result', $result);
         } else {
             $file_contents = $file_version->getFileContents();
             $this->xml = simplexml_load_string($file_contents);
             $migrate->import($object, $this->xml);
             $this->set('result', $migrate->result);
         }
     }
     // set mode
     $this->set('mode', $mode);
 }