/** * 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('street')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired')); // no errors? if ($this->frm->isCorrect()) { // build item $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['street'] = $this->frm->getField('street')->getValue(); $item['number'] = $this->frm->getField('number')->getValue(); $item['zip'] = $this->frm->getField('zip')->getValue(); $item['city'] = $this->frm->getField('city')->getValue(); $item['country'] = $this->frm->getField('country')->getValue(); // 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; // insert the item $id = BackendLocationModel::insert($item); // add search index // if(is_callable(array('BackendSearchModel', 'addIndex'))) BackendSearchModel::addIndex($this->getModule(), (int) $id, array('title' => $item['title'], 'text' => $item['text'])); // everything is saved, so redirect to the overview if ($item['lat'] && $item['lng']) { // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $id); } else { $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id); } } } }
/** * Validate form */ private function validateForm() { if ($this->frm->isSubmitted()) { if ($this->frm->isCorrect()) { if (!empty($this->records)) { $teller = 0; foreach ($this->records as $key => $record) { if ($teller < $this->frm->getField("number_of_items")->getValue()) { $data = array(); //--Create url $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($record['address'] . ', ' . $record['zipcode'] . ' ' . $record['city'] . ', ' . \SpoonLocale::getCountry($record['country'], BL::getWorkingLanguage())) . '&sensor=false'; //--Get lat $geocode = json_decode(\SpoonHTTP::getContent($url)); //--Sleep between the requests sleep(0.05); //--Check result $data['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $data['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; if ($data['lat'] != null) { BackendAddressesModel::update($record['id'], $data); $this->response .= "<strong>" . $record['company'] . "</strong> - " . $record['address'] . " " . $record['zipcode'] . " " . $record['city'] . " <i>(Lat: " . $data['lat'] . ", Lng: " . $data['lng'] . ")</i><br/>"; //--Delete from array unset($this->records[$key]); } else { $data['lat'] = "notfound"; $data['lng'] = "notfound"; BackendAddressesModel::update($record['id'], $data); $this->responseError .= "<strong>" . $record['company'] . "</strong> - " . $record['address'] . " " . $record['zipcode'] . " " . $record['city'] . "<br/>"; } } else { break; } //--Add teller $teller++; } $this->tpl->assign("responseError", $this->responseError); $this->tpl->assign("response", $this->response); } } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired')); if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['language'] = BL::getWorkingLanguage(); $item['extra_id'] = $this->record['extra_id']; $item['title'] = $this->frm->getField('title')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['street'] = $this->frm->getField('street')->getValue(); $item['number'] = $this->frm->getField('number')->getValue(); $item['zip'] = $this->frm->getField('zip')->getValue(); $item['city'] = $this->frm->getField('city')->getValue(); $item['country'] = $this->frm->getField('country')->getValue(); // check if it's neccessary to geocode again if ($this->record['lat'] === null || $this->record['lng'] === null || $item['street'] != $this->record['street'] || $item['number'] != $this->record['number'] || $item['zip'] != $this->record['zip'] || $item['city'] != $this->record['city'] || $item['country'] != $this->record['country']) { // 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; } else { $item['lat'] = $this->record['lat']; $item['lng'] = $this->record['lng']; } // insert the item $id = BackendLocationModel::update($item); // edit search index // @todo why is this commented out? // BackendSearchModel::editIndex($this->getModule(), (int) $id, array('title' => $item['title'], 'text' => $item['text'])); // everything is saved, so redirect to the overview if ($item['lat'] && $item['lng']) { // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($item['title']) . '&highlight=row-' . $id); } else { $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $item['id']); } } } }
/** * 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 */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); // 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')); } $this->meta->validate(); if ($this->frm->isCorrect()) { $item['meta_id'] = $this->meta->save(); $item['company'] = $fields['company']->getValue(); $item['name'] = $fields['name']->getValue(); $item['firstname'] = $fields['firstname']->getValue(); $item['email'] = $fields['email']->getValue(); $item['address'] = $fields['address']->getValue(); $item['zipcode'] = $fields['zipcode']->getValue(); $item['city'] = $fields['city']->getValue(); $item['country'] = $fields['country']->getValue(); $item['phone'] = $fields['phone']->getValue(); $item['fax'] = $fields['fax']->getValue(); $item['website'] = str_replace("http://", "", $fields['website']->getValue()); $item['text'] = $fields['text']->getValue(); $item['zipcodes'] = $fields['zipcodes']->getValue(); $item['remark'] = $fields['remark']->getValue(); //$item['assort'] = $fields['assort']->getValue(); //$item['open'] = $fields['open']->getValue(); //$item['closed'] = $fields['closed']->getValue(); //$item['visit'] = $fields['visit']->getValue(); //$item['size'] = $fields['size']->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['hidden'] = $fields['hidden']->getValue(); if ($item['country'] == '') { $item['country'] = 'BE'; } //--Create url $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; //--Get lat $geocode = json_decode(\SpoonHTTP::getContent($url)); //--Sleep between the requests sleep(0.05); //--Check result $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; // the image path $imagePath = FRONTEND_FILES_PATH . '/Addresses/Images'; // create folders if needed if (!\SpoonDirectory::exists($imagePath . '/Source')) { \SpoonDirectory::create($imagePath . '/Source'); } if (!\SpoonDirectory::exists($imagePath . '/128x128')) { \SpoonDirectory::create($imagePath . '/128x128'); } if (!\SpoonDirectory::exists($imagePath . '/400x300')) { \SpoonDirectory::create($imagePath . '/400x300'); } if (!\SpoonDirectory::exists($imagePath . '/800x')) { \SpoonDirectory::create($imagePath . '/800x'); } // image provided? if ($this->frm->getField('image')->isFilled()) { // build the image name $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension(); // upload the image & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']); } $item['id'] = BackendAddressesModel::insert($item); //--Add the languages foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) { $itemLanguage = array(); $itemLanguage['id'] = $item['id']; $itemLanguage['language'] = $language; $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue(); $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue(); BackendAddressesModel::insertLanguage($itemLanguage); } if (isset($fields["groups"])) { //--Get all the groups $groups = $fields["groups"]->getValue(); foreach ($groups as $value) { $groupAddress = array(); $groupAddress["address_id"] = $item['id']; $groupAddress["group_id"] = $value; //--Add user to the group BackendAddressesModel::insertAddressToGroup($groupAddress); } } BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name'])); BackendModel::triggerEvent($this->getModule(), 'after_add', $item); $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']); } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); // $fields['name']->isFilled(BL::err('FieldIsRequired')); $this->meta->validate(); if ($this->frm->isCorrect()) { $item['meta_id'] = $this->meta->save(); $item['company'] = $fields['company']->getValue(); $item['name'] = $fields['name']->getValue(); $item['firstname'] = $fields['firstname']->getValue(); $item['email'] = $fields['email']->getValue(); $item['address'] = $fields['address']->getValue(); $item['zipcode'] = $fields['zipcode']->getValue(); $item['city'] = $fields['city']->getValue(); $item['country'] = $fields['country']->getValue(); $item['phone'] = $fields['phone']->getValue(); $item['fax'] = $fields['fax']->getValue(); $item['website'] = str_replace("http://", "", $fields['website']->getValue()); $item['zipcodes'] = $fields['zipcodes']->getValue(); $item['remark'] = $fields['remark']->getValue(); //$item['text'] = $fields['text']->getValue(); //$item['assort'] = $fields['assort']->getValue(); //$item['open'] = $fields['open']->getValue(); //$item['closed'] = $fields['closed']->getValue(); //$item['visit'] = $fields['visit']->getValue(); //$item['size'] = $fields['size']->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['hidden'] = $fields['hidden']->getValue(); if ($item['country'] == '') { $item['country'] = 'BE'; } //--Create url $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; //--Get lat $geocode = json_decode(\SpoonHTTP::getContent($url)); //--Sleep between the requests sleep(0.05); //--Check result $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; $item['image'] = $this->record['image']; // the image path $imagePath = FRONTEND_FILES_PATH . '/Addresses/Images'; // create folders if needed if (!\SpoonDirectory::exists($imagePath . '/Source')) { \SpoonDirectory::create($imagePath . '/Source'); } if (!\SpoonDirectory::exists($imagePath . '/128x128')) { \SpoonDirectory::create($imagePath . '/128x128'); } if (!\SpoonDirectory::exists($imagePath . '/400x300')) { \SpoonDirectory::create($imagePath . '/400x300'); } if (!\SpoonDirectory::exists($imagePath . '/800x')) { \SpoonDirectory::create($imagePath . '/800x'); } // if the image should be deleted if ($this->frm->getField('delete_image')->isChecked()) { // delete the image \SpoonFile::delete($imagePath . '/Source/' . $item['image']); // reset the name $item['image'] = null; } // new image given? if ($this->frm->getField('image')->isFilled()) { // delete the old image \SpoonFile::delete($imagePath . '/Source/' . $this->record['image']); // build the image name $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension(); // upload the image & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']); } elseif ($item['image'] != null) { // get the old file extension $imageExtension = \SpoonFile::getExtension($imagePath . '/Source/' . $item['image']); // get the new image name $newName = $this->meta->getURL() . '.' . $imageExtension; // only change the name if there is a difference if ($newName != $item['image']) { // loop folders foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) { // move the old file to the new name \SpoonFile::move($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName); } // assign the new name to the database $item['image'] = $newName; } } BackendAddressesModel::update($this->id, $item); $item['id'] = $this->id; //--Add the languages foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) { $itemLanguage = array(); $itemLanguage['id'] = $item['id']; $itemLanguage['language'] = $language; $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue(); $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue(); BackendAddressesModel::updateLanguage($itemLanguage); } if (isset($fields["groups"])) { //--Get all the groups $groups = $fields["groups"]->getValue(); BackendAddressesModel::deleteGroupsFromAddress($item['id']); foreach ($groups as $value) { $groupAddress = array(); $groupAddress["address_id"] = $item['id']; $groupAddress["group_id"] = $value; //--Add user to the group BackendAddressesModel::insertAddressToGroup($groupAddress); } } BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name'])); BackendModel::triggerEvent($this->getModule(), 'after_edit', $item); $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']); } } }