Exemple #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');
         }
     }
 }