Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendAddressesModel::existsGroup($this->id)) {
         parent::execute();
         $this->record = (array) BackendAddressesModel::getGroup($this->id);
         BackendAddressesModel::deleteGroup($this->id);
         BackendAddressesModel::deleteAddressesFromGroup($this->id);
         BackendModel::triggerEvent($this->getModule(), 'after_delete_group', array('id' => $this->id));
         $this->redirect(BackendModel::createURLForAction('groups') . '&report=deleted&var=' . urlencode($this->record['title']));
     } else {
         $this->redirect(BackendModel::createURLForAction('groups') . '&error=non-existing');
     }
 }
Example #2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendAddressesModel::exists($this->id)) {
         parent::execute();
         $this->record = (array) BackendAddressesModel::get($this->id);
         BackendAddressesModel::delete($this->id);
         BackendAddressesModel::deleteGroupsFromAddress($this->id);
         // delete the image
         \SpoonFile::delete(FRONTEND_FILES_PATH . '/Addresses/Images/Source/' . $this->record['image']);
         BackendSearchModel::removeIndex($this->getModule(), $this->id);
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         $this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['id']));
     } else {
         $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
     }
 }
Example #3
0
 /**
  * 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);
             }
         }
     }
 }
Example #4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $newIdSequence = trim(SpoonFilter::getPostValue('new_id_sequence', null, '', 'string'));
     // list id
     $ids = (array) explode(',', rtrim($newIdSequence, ','));
     // loop id's and set new sequence
     foreach ($ids as $i => $id) {
         // build item
         $id = (int) $id;
         // change sequence
         $item['sequence'] = $i + 1;
         // update sequence
         if (BackendAddressesModel::existsGroup($id)) {
             BackendAddressesModel::updateGroup($id, $item);
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the ids and split them
     $ids = explode(',', trim(SpoonFilter::getPostValue('ids', null, '', 'string')));
     $group_id = SpoonFilter::getPostValue('group_id', null, '', 'int');
     //--Check if the id is not empty
     if (!empty($ids)) {
         //--Set the sequence to 1
         $sequence = 1;
         //--Loop the id's
         foreach ($ids as $address_id) {
             //--Set the item array
             $item = array();
             $item["sequence"] = $sequence;
             BackendAddressesModel::exists($address_id) ? BackendAddressesModel::updateSequence($address_id, $group_id, $item) : null;
             //--Add the sequence for each id
             $sequence++;
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Example #6
0
 /**
  * Execute the actions
  */
 public function execute()
 {
     parent::execute();
     //--Get all the addresses
     $addresses = BackendAddressesModel::getAllAddresses(1);
     foreach ($addresses as &$address) {
         $address = BackendAddressesModel::get($address['id']);
         foreach ($address as &$row) {
             $row = $row == "" ? "-" : $row;
         }
     }
     foreach ($addresses as $address) {
         set_time_limit(10);
         if (filter_var($address['email'], FILTER_VALIDATE_EMAIL) && $address['send_mail'] == 0) {
             //--Send mail for the address
             BackendMailer::addEmail("Nieuwe website Namev.be met uw eigen bedrijfs-pagina", BACKEND_MODULE_PATH . '/layout/templates/mails/send_email.tpl', $address, '*****@*****.**', $address['company']);
             //								BackendMailer::addEmail("Nieuwe website Namev.be met uw eigen bedrijfs-pagina", BACKEND_MODULE_PATH . '/layout/templates/mails/send_email.tpl', $address, '*****@*****.**', $address['company']);
             //				BackendMailer::addEmail("Nieuwe website Namev.be met uw eigen bedrijfs-pagina", BACKEND_MODULE_PATH . '/layout/templates/mails/send_email.tpl', $address, $address['email'], $address['company']);
             BackendModel::getContainer()->get('database')->update('addresses', array("send_mail" => 1), 'id = ?', (int) $address['id']);
             die;
         }
     }
     //--Update the address row when e-mail is send
 }
Example #7
0
 /**
  * Load the form.
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('filter', BackendModel::createURLForAction(), 'get');
     // add fields
     $this->frm->addText('email', $this->filter['email']);
     $this->frm->addText('name', $this->filter['name']);
     // get categories
     $groups = BackendAddressesModel::getAllGroupsForDropdown();
     $groups = array("0" => "") + $groups;
     // multiple categories?
     if (count($groups) > 1) {
         // create element
         $this->frm->addDropdown('group', $groups, $this->filter["group"]);
         $this->frm->getField('group')->setDefaultElement('');
     }
     // manually parse fields
     $this->frm->parse($this->tpl);
 }
Example #8
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         $fields['title']->isFilled(BL::err('FieldIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['title'] = $fields['title']->getValue();
             $item['parent_id'] = $fields['group']->getValue() != 0 ? $fields['group']->getValue() : null;
             BackendAddressesModel::updateGroup($this->id, $item);
             $item['id'] = $this->id;
             if (isset($fields["addresses"])) {
                 //--Delete addresses for that group
                 BackendAddressesModel::deleteAddressesFromGroup($this->id);
                 //--Get all the users
                 $addresses = $fields["addresses"]->getValue();
                 foreach ($addresses as $value) {
                     $addressGroup = array();
                     $addressGroup["group_id"] = $this->id;
                     $addressGroup["address_id"] = $value;
                     //--Add user to the group
                     BackendAddressesModel::insertAddressToGroup($addressGroup);
                 }
             }
             BackendModel::triggerEvent($this->getModule(), 'after_edit_group', $item);
             $this->redirect(BackendModel::createURLForAction('groups') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Example #9
0
 private function loadFilterForm()
 {
     // get categories
     $groups = BackendAddressesModel::getAllGroupsTree();
     //$groups = array('') + $groups;
     // multiple categories?
     if (count($groups) > 1) {
         // create form
         $frm = new BackendForm('filter', null, 'get', false);
         // create element
         $frm->addDropdown('group', $groups, $this->groupId);
         //			$frm->getField('category')->setDefaultElement('');
         // parse the form
         $frm->parse($this->tpl);
     }
     // parse category
     if (!empty($this->category)) {
         $this->tpl->assign('filterGroup', $this->group);
     }
 }
Example #10
0
 public function execute()
 {
     parent::execute();
     $txtText = \SpoonFile::getContent(BACKEND_MODULE_PATH . "/fabrikanten.txt");
     $arrText = explode("\n", $txtText);
     $arrShop = array();
     $arrShops = array();
     $arrCompanyNames = array();
     foreach ($arrText as $intKey => $strValue) {
         //--Check for phone
         $strPosTelephone = strpos($strValue, "Tel.:");
         if ($strPosTelephone !== false) {
             $arrShop["phone"] = trim(str_replace("Tel.:", "", substr($strValue, $strPosTelephone)));
         }
         //--Check for fax
         $strPosFax = strpos($strValue, "Fax:");
         if ($strPosFax !== false) {
             $arrShop["fax"] = trim(str_replace("Fax:", "", substr($strValue, $strPosFax)));
         }
         //--Find the e-mailaddress in the string
         if (!isset($arrShopFinal["email"])) {
             preg_match("/[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})/i", $strValue, $matchesEmail);
             if (!empty($matchesEmail)) {
                 $arrShop["email"] = $matchesEmail[0];
             }
         }
         //--Find the website address
         if (!isset($arrShopFinal["website"])) {
             preg_match("/www\\.[a-zA-Z0-9-]+\\.[a-z]{2,7}/i", $strValue, $matchesWebsite);
             if (!empty($matchesWebsite)) {
                 $arrShop["website"] = $matchesWebsite[0];
             }
         }
         //--Check the value
         if ($strValue != "" && !in_array($strValue, $arrCompanyNames) && $arrText[$intKey + 1] == "" && $arrText[$intKey + 2] == "" && empty($matchesWebsite)) {
             //--Check if shop is empty
             if (!empty($arrShop)) {
                 //--Add shop to shops-array
                 $arrShops[] = $arrShop;
             }
             $arrCity = explode(" ", $arrText[$intKey + 4], 2);
             //--New shop
             $arrShop = array();
             $arrShop['company'] = $strValue;
             $arrShop['address'] = ucwords(strtolower($arrText[$intKey + 3]));
             $arrShop['zipcode'] = ucwords(strtolower($arrCity[0]));
             $arrShop['city'] = ucwords(strtolower($arrCity[1]));
             $arrShop['country'] = "BE";
             //--Split zipcode
             $arrCountry = explode("-", $arrShop['zipcode']);
             if (count($arrCountry) > 1) {
                 $arrShop['country'] = strtoupper($arrCountry[0]);
             }
             //--Add companyname to the values
             $arrCompanyNames[] = $strValue;
         }
     }
     //--Loop all the shops
     foreach ($arrShops as $row) {
         $meta = array();
         $meta["keywords"] = $row["company"];
         $meta["description"] = "import-address";
         //$row["company"];
         $meta["title"] = $row["company"];
         $meta["url"] = $row["company"];
         //--Replace the values with utf8
         foreach ($row as &$value) {
             $value = utf8_encode($value);
         }
         //--Insert meta
         $row["meta_id"] = BackendAddressesModel::insertMeta($meta);
         //--Add address to the database
         $address_id = BackendAddressesModel::insert($row);
         //--Add address to group
         $address = array("address_id" => $address_id, "group_id" => 2);
         BackendAddressesModel::insertAddressToGroup($address);
     }
 }
Example #11
0
 /**
  * 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']);
         }
     }
 }
Example #12
0
 public function execute()
 {
     parent::execute();
     $txtText = \SpoonFile::getContent(BACKEND_MODULE_PATH . "/meubelwinkels.txt");
     $arrText = explode("\n", $txtText);
     $strShop = "";
     $arrShops = array();
     $arrShopsFinal = array();
     $arrElements = array("company", "phone", "zipcode", "city", "address", "contact", "email", "website", "fax", "vat", "assort", "m�", "open", "gesloten", "visit");
     $arrElementsDash = array("assort", "m�", "open", "gesloten", "visit");
     foreach ($arrText as $line) {
         //--Check if the line is only a zipcode or pagenumbers (1000 or 52 53)
         if (preg_match("/^\\d+\$/", $line) || preg_match("/^[0-9 ]+\$/", $line)) {
             continue;
         }
         //--Search for T : in the line (this is the first line of the address)
         if (strpos($line, "T :") !== false) {
             //--If line is not empty, add it to the array
             if (!empty($strShop)) {
                 $arrShops[] = $strShop;
             }
             $strShop = "";
         }
         //--Add the line + add a marker [LINE]
         $strShop .= $line . "[LINE]";
     }
     //--Loop all the shops
     foreach ($arrShops as $shop) {
         //--Explode the shop with [LINE]
         $arrShop = explode("[LINE]", $shop);
         $arrShopFinal = array();
         //--Get the phone number and name of the shop
         $strPosTelephone = strpos($arrShop[0], "T :");
         //--Create array
         $arrShopFinal["company"] = ucwords(mb_strtolower(substr($arrShop[0], 0, $strPosTelephone)));
         $arrShopFinal["phone"] = trim(str_replace("T :", "", substr($arrShop[0], $strPosTelephone)));
         //--Get the address
         $strAddress = ucwords(mb_strtolower($arrShop[1]));
         //--Get position of the space
         $strPosSpaceZipcode = strpos($strAddress, " ");
         //--Add the zipcode
         $arrShopFinal["zipcode"] = substr($strAddress, 0, $strPosSpaceZipcode);
         //--Alter the address-string
         $strAddress = substr($strAddress, $strPosSpaceZipcode);
         //--Search comma
         $strPosCommaCity = strpos($strAddress, ",");
         //--Add the city
         $arrShopFinal["city"] = substr($strAddress, 0, $strPosCommaCity);
         //--Add the address
         $arrShopFinal["address"] = trim(substr($strAddress, $strPosCommaCity + 1));
         //--Unset first and second item
         unset($arrShop[0]);
         unset($arrShop[1]);
         //--Loop the shop
         foreach ($arrShop as $key => $row) {
             //--Get the contact
             if (!isset($arrShopFinal["contact"]) && strpos($row, "contact:") !== false) {
                 $arrShopFinal["contact"] = ucwords(mb_strtolower(trim(substr($row, 8))));
             }
             //--Find the e-mailaddress in the string
             if (!isset($arrShopFinal["email"])) {
                 preg_match("/[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})/i", $row, $matches);
                 if (!empty($matches)) {
                     $arrShopFinal["email"] = $matches[0];
                 }
             }
             //--Find the website address
             if (!isset($arrShopFinal["website"])) {
                 preg_match("/www\\.[a-zA-Z0-9-]+\\.[a-z]{2,7}/i", $row, $matches);
                 if (!empty($matches)) {
                     $arrShopFinal["website"] = $matches[0];
                 }
             }
             //--Find the fax
             if (!isset($arrShopFinal["fax"])) {
                 preg_match("/F: ([\\s0-9]+)/i", $row, $matches);
                 if (!empty($matches)) {
                     $arrShopFinal["fax"] = $matches[1];
                 }
             }
             //--Find the VAT
             if (!isset($arrShopFinal["btw"])) {
                 preg_match("/BTW : ([A-Z]{2}[\\s]*[0-9-\\.\\s]+)/i", $row, $matches);
                 if (!empty($matches)) {
                     $arrShopFinal["vat"] = $matches[1];
                 }
             }
             //--Check if the dash is for a numeric value (not  - assort:)
             preg_match("/([0-9]{1}[\\s]-[\\s][0-9]{1})/i", $row, $matches);
             if (!empty($matches)) {
                 foreach ($matches as $match) {
                     $strMatchReplace = str_replace(" - ", "-", $match);
                     $row = str_replace($match, $strMatchReplace, $row);
                 }
             }
             //--Split the text with " - ";
             $arrDashes = explode(" - ", $row);
             //--Check if there are elements
             if (!empty($arrDashes)) {
                 //--Loop the different pieces
                 foreach ($arrDashes as $dash) {
                     //--Loop the elements that are possible for the dash-element
                     foreach ($arrElementsDash as $element) {
                         //--Check if the element is found, if true, add the element to the array
                         if (strpos($dash, $element . ":") !== false) {
                             $arrShopFinal[$element] = str_replace($element . ":", "", $dash);
                         }
                     }
                 }
             }
         }
         //--Check if all elements are filled in
         foreach ($arrElements as $element) {
             //--If key not exists, add an empty value to it
             if (!isset($arrShopFinal[$element])) {
                 //--Fill in empty value
                 $arrShopFinal[$element] = "";
             } else {
                 //--Replace to utf8
                 $arrShopFinal[$element] = trim($arrShopFinal[$element]);
                 //--Replace ? to '
                 $arrShopFinal[$element] = str_replace("?", "'", $arrShopFinal[$element]);
             }
         }
         //--Replace m� by size (for the database)
         $arrShopFinal["size"] = $arrShopFinal["m�"];
         unset($arrShopFinal["m�"]);
         //--Replace gesloten by closed (for the database)
         $arrShopFinal["closed"] = $arrShopFinal["gesloten"];
         unset($arrShopFinal["gesloten"]);
         $arrShopFinal["country"] = substr($arrShopFinal["vat"], 0, 2);
         $arrShopFinal["country"] = $arrShopFinal["country"] == "" ? "BE" : $arrShopFinal["country"];
         //--Add final shop to all shops
         $arrShopsFinal[] = $arrShopFinal;
     }
     //--Loop all the shops
     foreach ($arrShopsFinal as $row) {
         $meta = array();
         $meta["keywords"] = $row["company"];
         $meta["description"] = "import-address";
         //$row["company"];
         $meta["title"] = $row["company"];
         $meta["url"] = $row["company"];
         //--Replace the values with utf8
         foreach ($row as &$value) {
             $value = utf8_encode($value);
         }
         //--Insert meta
         $row["meta_id"] = BackendAddressesModel::insertMeta($meta);
         //--Add address to the database
         $address_id = BackendAddressesModel::insert($row);
         //--Add address to group
         $address = array("address_id" => $address_id, "group_id" => 1);
         BackendAddressesModel::insertAddressToGroup($address);
     }
     die;
 }
Example #13
0
 /**
  * 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']);
         }
     }
 }