/** * @return bool */ private function isValid() { $fields = $this->form->getFields(); if (!$fields['start_date']->isFilled(Language::err('FieldIsRequired')) || !$fields['end_date']->isFilled(Language::err('FieldIsRequired'))) { return $this->form->isCorrect(); } if (!$fields['start_date']->isValid(Language::err('DateIsInvalid')) || !$fields['end_date']->isValid(Language::err('DateIsInvalid'))) { return $this->form->isCorrect(); } $newStartDate = Model::getUTCTimestamp($fields['start_date']); $newEndDate = Model::getUTCTimestamp($fields['end_date']); // startdate cannot be before 2005 (earliest valid google startdate) if ($newStartDate < mktime(0, 0, 0, 1, 1, 2005)) { $fields['start_date']->setError(Language::err('DateRangeIsInvalid')); } // enddate cannot be in the future if ($newEndDate > time()) { $fields['start_date']->setError(Language::err('DateRangeIsInvalid')); } // enddate cannot be before the startdate if ($newStartDate > $newEndDate) { $fields['start_date']->setError(Language::err('DateRangeIsInvalid')); } return $this->form->isCorrect(); }
/** * Validate the form. */ 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(); // get fields $ddmGroup = $this->frm->getField('group'); $txtExpirationDate = $this->frm->getField('expiration_date'); $txtExpirationTime = $this->frm->getField('expiration_time'); // fields filled? $ddmGroup->isFilled(BL::getError('FieldIsRequired')); if ($txtExpirationDate->isFilled()) { $txtExpirationDate->isValid(BL::getError('DateIsInvalid')); } if ($txtExpirationTime->isFilled()) { $txtExpirationTime->isValid(BL::getError('TimeIsInvalid')); } // no errors? if ($this->frm->isCorrect()) { // build item $values['profile_id'] = $this->id; $values['group_id'] = $ddmGroup->getSelected(); $values['starts_on'] = BackendModel::getUTCDate(); // only format date if not empty if ($txtExpirationDate->isFilled() && $txtExpirationTime->isFilled()) { // format date $values['expires_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($txtExpirationDate, $txtExpirationTime)); } // insert values $id = BackendProfilesModel::insertProfileGroup($values); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_profile_add_to_group', array('item' => $values)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $values['profile_id'] . '&report=membership-added&highlight=row-' . $id . '#tabGroups'); } } }
/** * 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 fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('categories')->isFilled(BL::err('CategoryIsRequired')); if ($this->frm->getField('width')->isFilled(BL::err('WidthIsRequired'))) { $this->frm->getField('width')->isNumeric(BL::err('NumericCharactersOnly')); } if ($this->frm->getField('height')->isFilled()) { $this->frm->getField('height')->isNumeric(BL::err('NumericCharactersOnly')); } $this->frm->getField('publish_on_date')->isValid(BL::getError('DateIsInvalid')); $this->frm->getField('publish_on_time')->isValid(BL::getError('TimeIsInvalid')); if ($this->frm->getField('filename')->isFilled()) { // correct extension? if ($this->frm->getField('filename')->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $this->frm->getField('filename')->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } // validate meta $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { // build item $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['meta_id'] = $this->meta->save(); $item['category_id'] = $this->frm->getField('categories')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['width'] = $this->frm->getField('width')->getValue(); $item['height'] = $this->frm->getField('height')->getValue(); // set height to null if empty if (empty($item['height'])) { $item['height'] = null; } $item['description'] = $this->frm->getField('description')->getValue(true); if ($this->frm->getField('filename')->isFilled()) { // create new filename $filename = $this->meta->getURL(); $filename .= '-' . uniqid(); $filename .= '-' . BL::getWorkingLanguage(); $filename .= '.' . $this->frm->getField('filename')->getExtension(); $item['filename'] = $filename; // create thumbnail $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $filename, 100, 100, false, false, 100); // @todo fix this $this->frm->getField('filename')->moveFile(FRONTEND_FILES_PATH . '/slideshow/' . $filename); } $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['sequence'] = BackendSlideshowModel::getMaximumGallerySequence($this->frm->getField('categories')->getValue()) + 1; $item['created_on'] = BackendModel::getUTCDate(); $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time'))); // insert the item $id = BackendSlideshowModel::insertGallery($item); // insert default settings BackendSlideshowModel::setSettings($id, $this->get('fork.settings')->getForModule('Slideshow')); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('AddImage') . '&report=added&id=' . $id); } } }
protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); if ($this->frm->isCorrect()) { $groups = array(); $profilesAll = 0; $profileGroups = array(); $users = array(); //--Get all the groups $groups = $fields["groups"]->getValue(); //--Check if mailengine groups are selected if (!empty($groups)) { //--Get the users for the groups $usersTemp = BackendMailengineModel::getUniqueEmailsFromGroups($groups); //--Add the groups if (is_array($usersTemp)) { $users = array_merge($users, $usersTemp); } } //--Check if there are profile groups checked if (isset($fields["profile_groups"])) { //--Get all the groups $profileGroups = $fields["profile_groups"]->getValue(); if (!empty($profileGroups)) { //--Get the users for the groups $usersTemp = BackendMailengineModel::getUniqueEmailsFromProfileGroups($profileGroups); //--Add the groups if (is_array($usersTemp)) { $users = array_merge($users, $usersTemp); } } } //--Check if all profiles is selected if (isset($fields["profiles_all"])) { if ($fields['profiles_all']->getValue() == 1) { $profilesAll = 1; $usersTemp = BackendMailengineModel::getUniqueEmailsFromProfiles(); if (is_array($usersTemp)) { $users = array_merge($users, $usersTemp); } } } //--Loop all the users and set the e-mail as key to remove duplicate e-mails $usersTemp = array(); foreach ($users as $user) { if (!isset($usersTemp[$user['email']])) { $usersTemp[$user['email']] = $user; } } //--Reset users-array to the unduplicate array $users = $usersTemp; //--Count users $countUsers = count($users); //--Create label $labelUsers = $countUsers == 1 ? BL::lbl("User") : BL::lbl("Users"); $this->tpl->assign("users", $users); $this->tpl->assign("countUsers", $countUsers); $this->tpl->assign("labelUsers", $labelUsers); if ($countUsers == 0) { $this->tpl->assign("errorUsers", true); $this->tpl->assign("back", BackendModel::createURLForAction($this->action, $this->module) . "&id=" . $this->id); } //--Add hidden fields to form $this->frm_review->addHidden("groups", implode(",", $groups)); $this->frm_review->addHidden("profiles_all", $profilesAll); $this->frm_review->addHidden("profile_groups", implode(",", $profileGroups)); $this->frm_review->addHidden("start_date", $fields["start_date"]->getValue()); $this->frm_review->addHidden("start_time", $fields["start_time"]->getValue()); //--Parse Form Review $this->parseFormReview(); } else { //--Parse Form Preview $this->parseFormPreview(); } } elseif ($this->frm_review->isSubmitted()) { //--Check if form_review is submitted $fields = $this->frm_review->getFields(); if ($this->frm_review->isCorrect()) { //--Insert mailing in ready-to-send-database $readyToSendId = BackendMailengineModel::insertMailingInReadyToSendDatabase($this->id, BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($fields['start_date'], $fields['start_time']))); //--Insert users in ready-to-send-database $groups = $fields["groups"]->getValue(); $profilesAll = $fields["profiles_all"]->getValue(); $profileGroups = $fields["profile_groups"]->getValue(); BackendMailengineModel::insertUsersInReadyToSendDatabase($readyToSendId, $groups, $profileGroups, $profilesAll); //--Redirect \SpoonHTTP::redirect(BackendModel::createURLForAction($this->action, $this->module) . "&id=" . $this->id . "&ready=1"); } } else { //--Parse Form Preview $this->parseFormPreview(); } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['title']->isFilled(BL::err('FieldIsRequired')); $fields['begin_date_date']->isFilled(BL::err('FieldIsRequired')); $fields['begin_date_time']->isFilled(BL::err('FieldIsRequired')); $fields['begin_date_date']->isValid(BL::err('DateIsInvalid')); $fields['begin_date_time']->isValid(BL::err('TimeIsInvalid')); $fields['end_date_date']->isFilled(BL::err('FieldIsRequired')); $fields['end_date_time']->isFilled(BL::err('FieldIsRequired')); $fields['end_date_date']->isValid(BL::err('DateIsInvalid')); $fields['end_date_time']->isValid(BL::err('TimeIsInvalid')); $fields['category_id']->isFilled(BL::err('FieldIsRequired')); if ($fields['price']->isFilled()) { $fields['price']->isPrice(BL::err('InvalidValue')); } // validate meta $this->meta->validate(); $this->media->validate(); if ($this->frm->isCorrect()) { $item['id'] = $this->id; $item['language'] = BL::getWorkingLanguage(); $item['title'] = $fields['title']->getValue(); $item['text'] = $fields['text']->getValue(); $item['introduction'] = $fields['introduction']->getValue(); $item['begin_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('begin_date_date'), $this->frm->getField('begin_date_time'))); $item['end_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('end_date_date'), $this->frm->getField('end_date_time'))); $item['category_id'] = $this->frm->getField('category_id')->getValue(); $item['price'] = $fields['price']->getValue(); $item['whole_day'] = $fields['whole_day']->getChecked() ? 'Y' : 'N'; $item['recurring'] = $fields['recurring']->getChecked() ? 'Y' : 'N'; $item['allow_subscriptions'] = $fields['subscriptions']->getValue(); $item['google_maps'] = $fields['google_maps']->getChecked() ? 'Y' : 'N'; $item['location_name'] = $fields['name']->getValue(); $item['street'] = $fields['street']->getValue(); $item['number'] = $fields['number']->getValue(); $item['zip'] = $fields['zip']->getValue(); $item['city'] = $fields['city']->getValue(); $item['country'] = $fields['country']->getValue(); $item['meta_id'] = $this->meta->save(); // geocode address $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['street'] . ' ' . $item['number'] . ', ' . $item['zip'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; $geocode = json_decode(\SpoonHTTP::getContent($url)); $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; // update item BackendAgendaModel::update($item); $item['id'] = $this->id; // recurring item if ($item['recurring'] == 'Y') { $recurringItem['id'] = $this->recurringOptions['id']; $recurringItem['agenda_id'] = $item['id']; $recurringItem['type'] = $fields['type']->getValue(); $recurringItem['interval'] = $fields['interval']->getValue(); $recurringItem['ends_on'] = $fields['ends_on']->getValue(); // if recurring type is weekly, get days checked if ($recurringItem['type'] == 1) { $days = $fields['days']->getChecked(); $recurringItem['days'] = implode(",", $days); } // if item ends on x amount of times if ($recurringItem['ends_on'] == 1) { $recurringItem['frequency'] = $fields['frequency']->getValue(); } else { if ($recurringItem['ends_on'] == 2) { // item ends on specific date // check date/time fields if ($fields['recurr_end_date_date']->isFilled() || $fields['recurr_end_date_time']->isFilled()) { $recurringItem['end_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('recurr_end_date_date'), $this->frm->getField('recurr_end_date_time'))); } } } // update if options exist if (BackendAgendaModel::existsRecurringOptions($recurringItem['id'], $recurringItem['agenda_id'])) { BackendAgendaModel::updateRecurringOptions($recurringItem); } else { // insert new options BackendAgendaModel::insertRecurringOptions($recurringItem); } } // add search index BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'Text' => $item['text'])); BackendModel::triggerEvent($this->getModule(), 'after_edit', $item); $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']); } } }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // get the status $status = \SpoonFilter::getPostValue('status', array('active', 'draft'), 'active'); // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid')); $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid')); $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired')); // validate meta $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['meta_id'] = $this->meta->save(); // this is used to let our model know the status (active, archive, draft) of the edited item $item['revision_id'] = $this->record['revision_id']; $item['category_id'] = (int) $this->frm->getField('category_id')->getValue(); $item['user_id'] = $this->frm->getField('user_id')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['introduction'] = $this->frm->getField('introduction')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time'))); $item['edited_on'] = BackendModel::getUTCDate(); $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N'; $item['status'] = $status; if ($this->imageIsAllowed) { $item['image'] = $this->record['image']; // the image path $imagePath = FRONTEND_FILES_PATH . '/blog/images'; // create folders if needed $fs = new Filesystem(); $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128')); // If the image should be deleted, only the database entry is refreshed. // The revision should keep it's file. if ($this->frm->getField('delete_image')->isChecked()) { // reset the name $item['image'] = null; } // new image given? if ($this->frm->getField('image')->isFilled()) { // build the image name // we use the previous revision-id in the filename to make the filename unique between // the different revisions, to prevent that a new file would // overwrite images of previous revisions that have the same title, and thus, the same filename $item['image'] = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $this->frm->getField('image')->getExtension(); // upload the image & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']); } elseif ($item['image'] != null) { // generate the new filename $image = new File($imagePath . '/source/' . $item['image']); $newName = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $image->getExtension(); // extract the filenames excluding …-[language]-[revision-id].jpg // to properly compare them to eachother $regex = '/(.*)-[a-z]{2}-[0-9]+\\.(.*)/'; // only copy if the new name differs from the old filename if (preg_replace($regex, '$1', $newName) != preg_replace($regex, '$1', $item['image'])) { // loop folders foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) { $fs->copy($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName); } // assign the new name to the database $item['image'] = $newName; } } } else { $item['image'] = null; } // update the item $item['revision_id'] = BackendBlogModel::update($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // recalculate comment count so the new revision has the correct count BackendBlogModel::reCalculateCommentCount(array($this->id)); // save the tags BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule()); // active if ($item['status'] == 'active') { // edit search index BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text'])); // ping if ($this->get('fork.settings')->get($this->URL->getModule(), 'ping_services', false)) { BackendModel::ping(SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'detail') . '/' . $this->meta->getURL()); } // build URL $redirectUrl = BackendModel::createURLForAction('Index') . '&report=edited&var=' . urlencode($item['title']) . '&id=' . $this->id . '&highlight=row-' . $item['revision_id']; } elseif ($item['status'] == 'draft') { // draft: everything is saved, so redirect to the edit action $redirectUrl = BackendModel::createURLForAction('Edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id']; } // append to redirect URL if ($this->categoryId != null) { $redirectUrl .= '&category=' . $this->categoryId; } // everything is saved, so redirect to the overview $this->redirect($redirectUrl); } } }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // get the status $status = \SpoonFilter::getPostValue('status', array('active', 'draft'), 'active'); // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid')); $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid')); $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired')); if ($this->frm->getField('category_id')->getValue() == 'new_category') { $this->frm->getField('category_id')->addError(BL::err('FieldIsRequired')); } if ($this->imageIsAllowed) { // validate the image if ($this->frm->getField('image')->isFilled()) { // image extension and mime type $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly')); $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly')); } } // validate meta $this->meta->validate(); if ($this->frm->isCorrect()) { // build item $item['id'] = (int) BackendBlogModel::getMaximumId() + 1; $item['meta_id'] = $this->meta->save(); $item['category_id'] = (int) $this->frm->getField('category_id')->getValue(); $item['user_id'] = $this->frm->getField('user_id')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['introduction'] = $this->frm->getField('introduction')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time'))); $item['created_on'] = BackendModel::getUTCDate(); $item['edited_on'] = $item['created_on']; $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N'; $item['num_comments'] = 0; $item['status'] = $status; // insert the item $item['revision_id'] = BackendBlogModel::insert($item); if ($this->imageIsAllowed) { // the image path $imagePath = FRONTEND_FILES_PATH . '/blog/images'; // create folders if needed $fs = new Filesystem(); $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128')); // image provided? if ($this->frm->getField('image')->isFilled()) { // build the image name $item['image'] = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $this->frm->getField('image')->getExtension(); // upload the image & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']); // add the image to the database without changing the revision id BackendBlogModel::updateRevision($item['revision_id'], array('image' => $item['image'])); } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // save the tags BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule()); // active if ($item['status'] == 'active') { // add search index BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text'])); // ping if ($this->get('fork.settings')->get($this->getModule(), 'ping_services', false)) { BackendModel::ping(SITE_URL . BackendModel::getURLForBlock('Blog', 'Detail') . '/' . $this->meta->getURL()); } // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['revision_id']); } elseif ($item['status'] == 'draft') { // draft: everything is saved, so redirect to the edit action $this->redirect(BackendModel::createURLForAction('Edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id']); } } } }
/** * 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 fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid')); $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid')); if ($this->frm->getField('width')->isFilled(BL::err('WidthIsRequired'))) { $this->frm->getField('width')->isNumeric(BL::err('NumericCharactersOnly')); } if ($this->frm->getField('height')->isFilled()) { $this->frm->getField('height')->isNumeric(BL::err('NumericCharactersOnly')); } if ($this->frm->getField('filename')->isFilled()) { // correct extension? if ($this->frm->getField('filename')->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $this->frm->getField('filename')->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } $this->frm->getField('categories')->isFilled(BL::err('CategoryIsRequired')); $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { //build settings item $settings['animation'] = $this->frm->getField('animation')->getValue(); $settings['direction'] = $this->frm->getField('direction')->getValue(); $settings['slideshow_speed'] = $this->frm->getField('slideshow_speed')->getValue(); $settings['animation_speed'] = $this->frm->getField('animation_speed')->getValue(); $settings['direction_navigation'] = $this->frm->getField('direction_navigation')->getChecked() ? 'true' : 'false'; $settings['control_navigation'] = $this->frm->getField('control_navigation')->getChecked() ? 'true' : 'false'; $settings['thumbnail_navigation'] = $this->frm->getField('thumbnail_navigation')->getChecked() ? 'true' : ''; $settings['keyboard'] = $this->frm->getField('keyboard')->getChecked() ? 'true' : 'false'; $settings['mousewheel'] = $this->frm->getField('mousewheel')->getChecked() ? 'true' : 'false'; $settings['touch'] = $this->frm->getField('touch')->getChecked() ? 'true' : 'false'; $settings['randomize'] = $this->frm->getField('randomize')->getChecked() ? 'true' : 'false'; $settings['auto_animate'] = $this->frm->getField('auto_animate')->getChecked() ? 'true' : 'false'; $settings['animation_loop'] = $this->frm->getField('animation_loop')->getChecked() ? 'true' : 'false'; // update settings BackendSlideshowModel::setSettings($this->id, $settings); // build item $item['id'] = $this->id; $item['meta_id'] = $this->meta->save(true); $item['language'] = $this->record['language']; $item['category_id'] = $this->frm->getField('categories')->getValue(); $item['title'] = $this->frm->getField('title')->getValue(); $item['description'] = $this->frm->getField('description')->getValue(true); $item['width'] = $this->frm->getField('width')->getValue(); $item['height'] = $this->frm->getField('height')->getValue(); // set height to null if empty if (empty($item['height'])) { $item['height'] = null; } $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time'))); $item['edited_on'] = BackendModel::getUTCDate(); $item['hidden'] = $this->frm->getField('hidden')->getValue(); // check if the category was changed if (!BackendSlideshowModel::getChangeCategory($this->id, $item['category_id'])) { // if so, adjust the sequence to the new category $item['sequence'] = BackendSlideshowModel::getMaximumGallerySequence($this->frm->getField('categories')->getValue()) + 1; } // if the image should be deleted if ($this->frm->getField('delete_image')->isChecked()) { $fs = new Filesystem(); // delete the image $fs->remove(FRONTEND_FILES_PATH . '/slideshow/' . $this->record['filename']); //delete thumbnail $fs->remove(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $this->record['filename']); // reset the name $item['filename'] = null; } if ($this->frm->getField('filename')->isFilled()) { // only delete the picture when there is one allready if (!empty($this->record['filename'])) { $fs = new Filesystem(); // delete the image $fs->remove(FRONTEND_FILES_PATH . '/slideshow/' . $this->record['filename']); //delete thumbnail $fs->remove(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $this->record['filename']); } // create new filename $filename = $this->meta->getURL(); $filename .= '-' . uniqid(); $filename .= '-' . BL::getWorkingLanguage(); $filename .= '.' . $this->frm->getField('filename')->getExtension(); // add filename to item $item['filename'] = $filename; // create thumbnail $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $filename, 100, 100, false, false, 100); // @todo fix this $this->frm->getField('filename')->moveFile(FRONTEND_FILES_PATH . '/slideshow/' . $filename); } // update gallery values in database BackendSlideshowModel::updateGallery($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // get the gallery data $item = BackendSlideshowModel::getGallery($this->id); // trace the action and get the ids $action = $this->frm->getField('action')->getValue(); $ids = (array) $_POST['id']; // Mass image delete action if ($action == 'delete') { foreach ($ids as $id) { // double check if the image exists if ($id !== null && BackendSlideshowModel::existsImage($id)) { // get item $this->record = BackendSlideshowModel::getImage($id); $fs = new Filesystem(); // delete the image and thumbnail $fs->remove(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $this->record['filename']); $fs->remove(FRONTEND_FILES_PATH . '/slideshow/' . $this->record['filename']); // delete item BackendSlideshowModel::deleteImage($this->record['id']); } } // redirect to edit, tab "images $this->redirect(BackendModel::createURLForAction('Edit') . '&report=deleted&id=' . $this->id . '#images'); } elseif ($action == 'publish') { // set new status BackendSlideshowModel::updatePublishedImage($ids); // redirect to edit, tab #images $this->redirect(BackendModel::createURLForAction('Edit') . '&report=saved&id=' . $this->id . '#images'); } elseif ($action == 'hide') { // set new status BackendSlideshowModel::updateHiddenImage($ids); // redirect to edit, tab #images $this->redirect(BackendModel::createURLForAction('Edit') . '&report=saved&id=' . $this->id . '#images'); } // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Index') . '&report=saved&var=' . urlencode($item['title']) . '&highlight=' . $item['id']); } } }