Example #1
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']);
         }
     }
 }
 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 #3
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 #4
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 #5
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']);
         }
     }
 }