<commit_before><?php
namespace Concrete\Package\BasicTablePackage\Src\FieldTypes;

use Concrete\Core\Block\BlockController;
use Concrete\Package\BasicTablePackage\Src\FieldTypes\Field as Field;
use Loader;
use Page;
use User;
use Core;
use File;
use Concrete\Controller\SinglePage\Dashboard\Blocks\Permissions as Permissions;
use Concrete\Core\Block\View\BlockView as View;

class FileField extends Field{

	public function __construct($sqlFieldname,$label, $postName){
		parent::__construct($sqlFieldname, $label, $postName);

	}

	public function setValue($value){
		$this->value = $value;
        return $this;
	}

	public function getTableView(){
		$f = $this->getFileObject();
		//$fp = new Permissions($f);
		if (/*$fp->canViewFile()*/true) {
			$c = Page::getCurrentPage();
			if($c instanceof Page) {
				$cID = $c->getCollectionID();
			}

			$returnString = "<a href=\"".View::url('/download_file', $this->getValue(),$cID)."\" target='_blank'>".stripslashes($this->getLinkText())."</a>";
			
		}else{
			$returnString = "keine Berechtigung";
		}

		$returnString.=$this->getHtmlErrorMsg();
		return $returnString;
	}


	public function getFormView($form){
		$al = Loader::helper('concrete/asset_library');
		$bf = null;
		if ($this->getValue() > 0) {
			$bf = $this->getFileObject();
		}
		$c = Page::getCurrentPage();

		$returnString = "
		<div class=\"form-group\">
		".$form->label($this->getPostName(), t('File'))."
		".$al->file($this->getPostName(), $this->getPostName(), t('Choose File'), $bf)."
		</div>";
		$valt = Loader::helper('validation/token');
		$token = $valt->generate();
		//$form->addHeaderItem('<script type="text/javascript">var CCM_SECURITY_TOKEN = \''.$token.'\';</script>');
		$returnString.='<script type="text/javascript">var CCM_SECURITY_TOKEN = \''.$token.'\';</script>';
		return $returnString;
	}



	public function getValue(){
		return $this->value;
	}





	public function validatePost($value){
		$this->value = $value;
		return true;
	}


	function getFileObject() {
		if(is_null($this->value)){
			return false;<commit_msg>add error message to file field<commit_after><?php
namespace Concrete\Package\BasicTablePackage\Src\FieldTypes;

use Concrete\Core\Block\BlockController;
use Concrete\Package\BasicTablePackage\Src\FieldTypes\Field as Field;
use Loader;
use Page;
use User;
use Core;
use File;
use Concrete\Controller\SinglePage\Dashboard\Blocks\Permissions as Permissions;
use Concrete\Core\Block\View\BlockView as View;

class FileField extends Field{

	public function __construct($sqlFieldname,$label, $postName){
		parent::__construct($sqlFieldname, $label, $postName);

	}

	public function setValue($value){
		$this->value = $value;
        return $this;
	}

	public function getTableView(){
		$f = $this->getFileObject();
		//$fp = new Permissions($f);
		if (/*$fp->canViewFile()*/true) {
			$c = Page::getCurrentPage();
			if($c instanceof Page) {
				$cID = $c->getCollectionID();
			}

			$returnString = "<a href=\"".View::url('/download_file', $this->getValue(),$cID)."\" target='_blank'>".stripslashes($this->getLinkText())."</a>";
			
		}else{
			$returnString = "keine Berechtigung";
		}

		$returnString.=$this->getHtmlErrorMsg();
		return $returnString;
	}


	public function getFormView($form){
		$al = Loader::helper('concrete/asset_library');
		$bf = null;
		if ($this->getValue() > 0) {
			$bf = $this->getFileObject();
		}
		$c = Page::getCurrentPage();

		$returnString = "
		<div class=\"form-group\">
		".$form->label($this->getPostName(), t('File'))."
		".$al->file($this->getPostName(), $this->getPostName(), t('Choose File'), $bf)."
		</div>";
		$valt = Loader::helper('validation/token');
		$token = $valt->generate();
		//$form->addHeaderItem('<script type="text/javascript">var CCM_SECURITY_TOKEN = \''.$token.'\';</script>');
		$returnString.='<script type="text/javascript">var CCM_SECURITY_TOKEN = \''.$token.'\';</script>';
        $returnString.=$this->getHtmlErrorMsg();
		return $returnString;
	}



	public function getValue(){
		return $this->value;
	}





	public function validatePost($value){
		$this->value = $value;
		return true;
	}


	function getFileObject() {
		if(is_null($this->value)){
			return false;
{'fraction_non_alphanumeric': 0.19268234735091472, 'fraction_numerical': 0.0004751722499406035, 'mean_word_length': 4.6208277703604805, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6173844', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1410, 'n_words': 265}