示例#1
0
 public function addToField(\Foundation\Form\Field $field)
 {
     if (!ini_get('file_uploads')) {
         throw new \Jazzee\Exception('File uploads are not turned on for this system and a PDFFileInputElement is being created', E_ERROR);
     }
     $element = $field->newElement('FileInput', 'el' . $this->_element->getId());
     $element->setLabel($this->_element->getTitle());
     $element->setInstructions($this->_element->getInstructions());
     $element->setFormat($this->_element->getFormat());
     $element->setDefaultValue($this->_element->getDefaultValue());
     if ($this->_element->isRequired()) {
         $validator = new \Foundation\Form\Validator\NotEmpty($element);
         $element->addValidator($validator);
     }
     if ($this->_controller->getConfig()->getVirusScanUploads()) {
         $element->addValidator(new \Foundation\Form\Validator\Virusscan($element));
     }
     $element->addValidator(new \Foundation\Form\Validator\PDF($element));
     $element->addValidator(new \Foundation\Form\Validator\PDFNotEncrypted($element));
     $element->addFilter(new \Foundation\Form\Filter\Blob($element));
     $max = $this->_controller->getConfig()->getMaximumApplicantFileUploadSize();
     if ($this->_element->getMax() and \Foundation\Utility::convertIniShorthandValue($this->_element->getMax()) <= $max) {
         $max = $this->_element->getMax();
     } else {
         $max = $this->_controller->getConfig()->getDefaultApplicantFileUploadSize();
     }
     $element->addValidator(new \Foundation\Form\Validator\MaximumFileSize($element, $max));
     return $element;
 }
示例#2
0
 /**
  * Before any action is taken do some basic setup
  * Look for out of bounds file uploads
  * Crate a navigation instance
  * Create the default layout varialbes so the layout doesn't have to guess if they are available
  * @return null
  */
 protected function beforeAction()
 {
     parent::beforeAction();
     /*
      When the php post_max_size attribute is exceed the POST array is blanked.
      So a check has to be done using the CONTENT_LENGTH superglobal against the post_max_size value on every request
     */
     if (!empty($_SERVER['CONTENT_LENGTH'])) {
         $max = \Foundation\Utility::convertIniShorthandValue(\ini_get('post_max_size'));
         if ($_SERVER['CONTENT_LENGTH'] > $max) {
             $this->addMessage('error', 'Your input has exceeded the maximum allowed size.  If you are trying to upload a file it is too large.  Please reduce your file size and try again');
         }
     }
     //add jquery
     $this->addScript('//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js');
     $this->addScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js');
     $this->addScript($this->path('resource/foundation/scripts/jquery.json.js'));
     $this->addScript($this->path('resource/foundation/scripts/jquery.cookie.js'));
     $this->addScript($this->path('resource/foundation/scripts/jquery.qtip.js'));
     $this->addScript($this->path('resource/foundation/scripts/anytime.js'));
     $this->addCss($this->path('resource/foundation/styles/jquery.qtip.css'));
     //add the Services javascript class
     $this->addScript($this->path('resource/scripts/classes/Services.class.js'));
     if ($this->_config->getBroadcastMessage()) {
         $this->addMessage('info', $this->_config->getBroadcastMessage());
     }
 }
示例#3
0
 /**
  * Attach PDF to applicant
  * @param integer $applicantId
  */
 public function actionAttachApplicantPdf($applicantId)
 {
     $applicant = $this->getApplicantById($applicantId);
     $form = new \Foundation\Form();
     $form->setAction($this->path("applicants/single/{$applicantId}/attachApplicantPdf"));
     $field = $form->newField();
     $field->setLegend('Attach PDF');
     $element = $field->newElement('FileInput', 'pdf');
     $element->setLabel('File');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $element->addValidator(new \Foundation\Form\Validator\PDF($element));
     $element->addValidator(new \Foundation\Form\Validator\PDFNotEncrypted($element));
     if ($this->_config->getVirusScanUploads()) {
         $element->addValidator(new \Foundation\Form\Validator\Virusscan($element));
     }
     $element->addFilter(new \Foundation\Form\Filter\Blob($element));
     if ($this->_config->getMaximumAdminFileUploadSize()) {
         $max = $this->_config->getMaximumAdminFileUploadSize();
     } else {
         $max = \Foundation\Utility::convertIniShorthandValue(\ini_get('upload_max_filesize'));
     }
     $element->addValidator(new \Foundation\Form\Validator\MaximumFileSize($element, $max));
     $form->newButton('submit', 'Attach PDF to Applicant');
     if (!empty($this->post)) {
         $this->setLayoutVar('textarea', true);
         if ($input = $form->processInput($this->post)) {
             $attachment = new \Jazzee\Entity\Attachment();
             $attachment->setAttachment($input->get('pdf'));
             $applicant->addAttachment($attachment);
             $this->_em->persist($attachment);
             //persist the applicant and answer to catch the last update
             $this->_em->persist($applicant);
             $this->_em->flush();
             //flush early so the attachment gets a good id for the preview
             $this->setLayoutVar('status', 'success');
         }
     }
     $this->setVar('result', array('attachments' => $this->getAttachments($applicant)));
     $this->setVar('form', $form);
     $this->loadView($this->controllerName . '/form');
 }
示例#4
0
 /**
  * set maximumAdminFileUploadSize
  * @var string $maximumAdminFileUploadSize
  */
 public function setMaximumAdminFileUploadSize($maximumAdminFileUploadSize)
 {
     if (\Foundation\Utility::convertIniShorthandValue($maximumAdminFileUploadSize) > \Foundation\Utility::convertIniShorthandValue(\ini_get('upload_max_filesize'))) {
         throw new \Jazzee\Exception('Configured Admin File Upload Size is larger than PHP upload_max_filesize');
     }
     $this->_maximumAdminFileUploadSize = \Foundation\Utility::convertIniShorthandValue($maximumAdminFileUploadSize);
 }
示例#5
0
 /**
  * Set the maximum upload size
  * do some checking to make sure we aren't futilely setting the size larger than one of the ini options can use 
  * @param integer $maxSize max size in bytes
  */
 public function setMaxSize($maxSize)
 {
     $maxSize = \Foundation\Utility::convertIniShorthandValue($maxSize);
     if ($maxSize > \Foundation\Utility::convertIniShorthandValue(\ini_get('upload_max_filesize'))) {
         throw new \Foundation\Exception('Attempting to set FileInput::maxSize to a value greater than PHP INI upload_max_filesize');
     }
     if ($maxSize > \Foundation\Utility::convertIniShorthandValue(\ini_get('post_max_size'))) {
         throw new \Foundation\Exception('Attempting to set FileInput::maxSize to a value greater than PHP INI post_max_size');
     }
     $this->maxSize = $maxSize;
 }