Exemple #1
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $image = $this->frm->getField('image');
         $this->frm->getField('title')->isFilled(BL::err('NameIsRequired'));
         if ($this->image['filename'] === null) {
             $image->isFilled(BL::err('FieldIsRequired'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build image record to insert
             $item['id'] = $this->id;
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['filename'] = $this->image['filename'];
             // set files path for this record
             $path = FRONTEND_FILES_PATH . '/' . $this->module . '/' . $this->itemId;
             $formats = array();
             $formats[] = array('size' => '64x64', 'force_aspect_ratio' => false);
             $formats[] = array('size' => '128x128', 'force_aspect_ratio' => false);
             if ($image->isFilled()) {
                 // only delete the picture when there is one allready
                 if (!empty($item['filename'])) {
                     $fs = new Filesystem();
                     $fs->remove(FRONTEND_FILES_PATH . '/agenda/thumbnails/' . $item['filename']);
                     $fs->remove(FRONTEND_FILES_PATH . '/agenda/' . $item['filename']);
                 }
                 // overwrite the filename
                 if ($item['filename'] === null) {
                     $item['filename'] = time() . '.' . $image->getExtension();
                 }
                 // add images
                 BackendAgendaHelper::addImages($image, $path, $item['filename'], $formats);
             }
             // save the item
             $id = BackendAgendaModel::saveImage($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_image', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('media') . '&agenda_id=' . $this->itemId . '&report=edited&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Exemple #2
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $image = $this->frm->getField('image');
         $this->frm->getField('title')->isFilled(BL::err('NameIsRequired'));
         $image->isFilled(BL::err('FieldIsRequired'));
         $settings = BackendModel::get('fork.settings')->getForModule('Agenda');
         // no errors?
         if ($this->frm->isCorrect()) {
             // build image record to insert
             $item['agenda_id'] = $this->item['id'];
             $item['title'] = $this->frm->getField('title')->getValue();
             // set files path for this record
             $path = FRONTEND_FILES_PATH . '/' . $this->module . '/' . $item['agenda_id'];
             // set formats
             $formats = array();
             $formats[] = array('size' => '64x64', 'allow_enlargement' => true, 'force_aspect_ratio' => false);
             $formats[] = array('size' => '128x128', 'allow_enlargement' => true, 'force_aspect_ratio' => false);
             $formats[] = array('size' => $settings['width1'] . 'x' . $settings['height1'], 'allow_enlargement' => $settings['allow_enlargement1'], 'force_aspect_ratio' => $settings['force_aspect_ratio1']);
             $formats[] = array('size' => $settings['width2'] . 'x' . $settings['height2'], 'allow_enlargement' => $settings['allow_enlargement2'], 'force_aspect_ratio' => $settings['force_aspect_ratio2']);
             $formats[] = array('size' => $settings['width3'] . 'x' . $settings['height3'], 'allow_enlargement' => $settings['allow_enlargement3'], 'force_aspect_ratio' => $settings['force_aspect_ratio3']);
             // set the filename
             $item['filename'] = time() . '.' . $image->getExtension();
             $item['sequence'] = BackendAgendaModel::getMaximumImagesSequence($item['agenda_id']) + 1;
             // add images
             BackendAgendaHelper::addImages($image, $path, $item['filename'], $formats);
             // save the item
             $item['id'] = BackendAgendaModel::saveImage($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_image', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('media') . '&agenda_id=' . $item['agenda_id'] . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }