/** * Validate the form * * @return void */ private 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 all images for ($i = 0; $i < $this->imageUploadFields; $i++) { // validate fields if ($this->frm->getField('image' . $i)->isFilled()) { // correct extension if ($this->frm->getField('image' . $i)->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $this->frm->getField('image' . $i)->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } } // no errors? if ($this->frm->isCorrect()) { // build item $item['language'] = $this->record['language']; $item['gallery_id'] = $this->id; for ($i = 0; $i < $this->imageUploadFields; $i++) { if ($this->frm->getField('image' . $i)->isFilled()) { // get the sequence everytime $item['sequence'] = BackendSlideshowModel::getMaximumImageSequence($this->id) + 1; // create new filename $filename = time() . $i . "." . $this->frm->getField('image' . $i)->getExtension(); // add filename to item $item['filename'] = $filename; // If height is not set, scale the image proportionally to the given width if ($this->record['height'] != 0) { // upload image width gallery dimensions $this->frm->getField('image' . $i)->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/' . $filename, $this->record['width'], $this->record['height'], true, false, 100); } else { $this->frm->getField('image' . $i)->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/' . $filename, $this->record['width'], null, true, true, 100); } // create thumbnail for later use $this->frm->getField('image' . $i)->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $filename, 100, 100, false, false, 100); // insert image values in database BackendSlideshowModel::insertImage($item); } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Edit') . '&report=saved&var=' . '&id=' . $this->id . '#images'); } } }