Beispiel #1
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
         $file = $this->frm->getField('file');
         $this->frm->getField('title')->isFilled(BL::err('NameIsRequired'));
         $file->isFilled(BL::err('FieldIsRequired'));
         // validate the file
         if ($this->frm->getField('file')->isFilled()) {
             // file extension
             $this->frm->getField('file')->isAllowedExtension($this->allowedExtensions, BL::err('FileExtensionNotAllowed'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build file record to insert
             $item['agenda_id'] = $this->item['id'];
             $item['title'] = $this->frm->getField('title')->getValue();
             // the file path
             $filePath = FRONTEND_FILES_PATH . '/' . $this->getModule() . '/' . $item['agenda_id'] . '/source';
             // create folders if needed
             if (!\SpoonDirectory::exists($filePath)) {
                 \SpoonDirectory::create($filePath);
             }
             // file provided?
             if ($file->isFilled()) {
                 // build the file name
                 $item['filename'] = time() . '.' . $file->getExtension();
                 // upload the file
                 $file->moveFile($filePath . '/' . $item['filename']);
             }
             $item['sequence'] = BackendAgendaModel::getMaximumFilesSequence($item['agenda_id']) + 1;
             // insert it
             $item['id'] = BackendAgendaModel::saveFile($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_file', 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'] . '#tabFiles');
         }
     }
 }
Beispiel #2
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
         $file = $this->frm->getField('file');
         $this->frm->getField('title')->isFilled(BL::err('NameIsRequired'));
         if ($this->file['filename'] === null) {
             $file->isFilled(BL::err('FieldIsRequired'));
         }
         // validate the file
         if ($this->frm->getField('file')->isFilled()) {
             // file extension
             $this->frm->getField('file')->isAllowedExtension($this->allowedExtensions, BL::err('FileExtensionNotAllowed'));
         }
         // 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->file['filename'];
             // the file path
             $filePath = FRONTEND_FILES_PATH . '/' . $this->getModule() . '/' . $this->itemId . '/source';
             if ($file->isFilled()) {
                 $item['filename'] = time() . '.' . $file->getExtension();
                 $file->moveFile($filePath . '/' . $item['filename']);
             }
             // save the item
             $id = BackendAgendaModel::saveFile($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_file', 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'] . '#tabFiles');
         }
     }
 }