Esempio n. 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;
 }
Esempio n. 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());
     }
 }
Esempio n. 3
0
 public function arrayDisplayValue(array $values)
 {
     $arr = array();
     foreach ($values as $position => $value) {
         $arr[] = \Foundation\Utility::ordinalValue($position + 1) . ' ' . $value['value'];
     }
     return empty($arr) ? null : implode(', ', $arr);
 }
Esempio n. 4
0
 /**
  * Create a demo element
  * @param \Jazzee\Entity\ElementType $type
  * $param \Doctrine\ORM\EntityManager $entityManager
  * @return \Jazzee\Entity\Element
  */
 protected function demoElement(\Jazzee\Entity\ElementType $type, \Doctrine\ORM\EntityManager $entityManager)
 {
     $element = new \Jazzee\Entity\Element();
     $element->setType($type);
     switch ($type->getClass()) {
         case '\\Jazzee\\Element\\CheckboxList':
         case '\\Jazzee\\Element\\RadioList':
         case '\\Jazzee\\Element\\SelectList':
             for ($i = 1; $i <= rand(5, 15); $i++) {
                 $item = new \Jazzee\Entity\ElementListItem();
                 $item->setWeight($i);
                 $item->activate();
                 $item->setValue(\Foundation\Utility::ordinalValue($i) . ' item');
                 $entityManager->persist($item);
                 $element->addItem($item);
             }
             break;
         case '\\Jazzee\\Element\\RankingList':
             for ($i = 1; $i <= rand(5, 15); $i++) {
                 $item = new \Jazzee\Entity\ElementListItem();
                 $item->setWeight($i);
                 $item->activate();
                 $item->setValue(\Foundation\Utility::ordinalValue($i) . ' item');
                 $entityManager->persist($item);
                 $element->addItem($item);
             }
             $element->setMin(1);
             $element->setMax(4);
             break;
         case '\\Jazzee\\Element\\Textarea':
             $element->setMax(500);
             break;
     }
     return $element;
 }
Esempio n. 5
0
/**
 * RankingList element form control
 * @package Foundation\form
 */
?>
<ol>
<?php 
for ($i = 0; $i < $element->getTotalItems(); $i++) {
    ?>
    <li>
      <div class='label'>
      <label for='<?php 
    print $element->getName() . '_' . $i;
    ?>
'><?php 
    print \Foundation\Utility::ordinalValue($i + 1);
    ?>
 choice:</label>
      </div>
      <div class='control<?php 
    if ($i < $element->getRequiredItems()) {
        print ' required';
    }
    ?>
'>
      <select name='<?php 
    print $element->getName();
    ?>
[]' id='<?php 
    print $element->getName() . '_' . $i;
    ?>
Esempio n. 6
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');
 }
Esempio n. 7
0
 public function preRender()
 {
     if (is_null($this->e->getFormat())) {
         $this->e->setFormat('Maximum file size: ' . \Foundation\Utility::convertBytesToString($this->ruleSet, 2) . '.');
     }
 }
Esempio n. 8
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);
 }
Esempio n. 9
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;
 }
Esempio n. 10
0
 /**
  * Check an IP address against the allowed address list
  * @param string $clientIp
  * @return boolean
  */
 protected function isAllowedIp($clientIp)
 {
     $allowedIps = explode(',', $this->_controller->getConfig()->getNoAuthIpAddresses());
     if (in_array($clientIp, $allowedIps)) {
         return true;
     }
     foreach ($allowedIps as $allowedIp) {
         if (\Foundation\Utility::ipInRange($clientIp, $allowedIp)) {
             return true;
         }
     }
     return false;
 }