<?php
namespace App\Controller;
use App\Entity\Actividad;
use App\Entity\ActividadFoto;
use App\Entity\ActividadI18n;
use App\Entity\Bodega;
use App\Entity\BodegaFoto;
use App\Entity\BodegaI18n;
use App\Entity\Dorigen;
use App\Entity\DorigenFoto;
use App\Entity\DorigenI18n;
use App\Entity\Idioma;
use App\Entity\Municipio;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Entity\RelActividadTipo;
use App\Entity\RelDorigenBodega;
use App\Entity\TipoI18n;
use App\Entity\Users;
use App\Utils\RandomStringGenerator;
use DateTime;
class HomeController extends AbstractController
{
/**
* @Route("/", name="home")
*/
public function index(): Response
{
if(!$this->getUser()){
return $this->redirectToRoute('app_login');
}else{
$em = $this->getDoctrine()->getManager();
$filtros = ['estado' => 1];
$dos = [];
$bodegas = [];
if ($this->getUser()->getRolesString() == "ROLE_DO") {
$filtros['dorigen'] = $this->getUser()->getDorigen()->getId();
$bodegas = $em->getRepository(Bodega::class)->findActivasByDorigen($this->getUser()->getDorigen()->getId());
} else if ($this->getUser()->getRolesString() == "ROLE_BODEGA") {
$filtros['bodega'] = $this->getUser()->getBodega()->getId();
$bodegas = $em->getRepository(Bodega::class)->findActivasByBodega($this->getUser()->getBodega()->getId());
} else {
$bodegas = $em->getRepository(Bodega::class)->findBy($filtros);
$dos = $em->getRepository(Dorigen::class)->findBy($filtros);
}
$actividades = $em->getRepository(Actividad::class)->findBy($filtros);
return $this->render('home/index.html.twig', [
'controller_name' => 'HomeController',
'user_name' => $this->getUser()->getName(),
'user_dorigen' => $this->getUser()->getDorigen() ? $this->getUser()->getDorigen()->getId() : null,
'user_bodega' => $this->getUser()->getBodega() ? $this->getUser()->getBodega()->getId() : null,
'user_role' => $this->getUser()->getRolesString(),
"total_actividades" => count($actividades),
"total_bodegas" => count($bodegas),
"total_dos" => count($dos)
]);
}
}
/**
* @Route("/politica", name="politica")
*/
public function politica(): Response
{
return $this->render('politicy/index.html.twig', []);
}
/**
* @Route("/termes", name="termes")
*/
public function termes(): Response
{
return $this->render('terms/index.html.twig', []);
}
/**
* @Route("/data_import/{tipo_import}", name="get_data_import", methods={"GET"})
*/
public function DataImport(Request $request){
$em = $this->getDoctrine()->getManager();
$responseCode = 200;
$lang = 'es';
$langData = $em->getRepository(Idioma::class)->findOneBy(['clave' => $lang]);
$langDataCA = $em->getRepository(Idioma::class)->findOneBy(['clave' => 'ca']);
$tipo_import = $request->get('tipo_import') ? $request->get('tipo_import') : 'actividad';
$customAlphabet = '0123456789ABCDEF';
/** Load $inputFileName to a Spreadsheet Object **/
$path = $this->getParameter('kernel.project_dir');
$inputFileName = $path.'/import/import.xlsx';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
// Set initial alphabet.
$generator = new RandomStringGenerator($customAlphabet);
$tokenLength = 32;
/* DO */
$dos = [];
$dosExist = [];
$dosExistCA = [];
$dosExistObject = [];
$dosData = $em->getRepository(Dorigen::class)->findAllImport($langData->getId());
foreach( $dosData as $d )
{
$dosExist[$d['url']] = ['id' => $d['id'], 'idI18n' => $d['idI18n']];
}
$dosDataCA = $em->getRepository(Dorigen::class)->findAllImport($langDataCA->getId());
foreach( $dosDataCA as $dCA )
{
$dosExistCA[$dCA['url']] = ['id' => $dCA['id'], 'idI18n' => $dCA['idI18n']];
}
$dosDataObjects = $em->getRepository(Dorigen::class)->findAll();
foreach( $dosDataObjects as $do )
{
$dosExistObject[$do->getId()] = $do;
}
if($tipo_import == 'dorigen'){
$dosExistObjectI18n = [];
$dosExistObjectI18nCA = [];
$dosExistObjectFoto = [];
$dosDataObjectsI18n = $em->getRepository(DorigenI18n::class)->findBy(['idioma' => $langData->getId()]);
foreach( $dosDataObjectsI18n as $doI18n )
{
$dosExistObjectI18n[$doI18n->getId()] = $doI18n;
}
$dosDataObjectsI18nCA = $em->getRepository(DorigenI18n::class)->findBy(['idioma' => $langDataCA->getId()]);
foreach( $dosDataObjectsI18nCA as $doI18nCA )
{
$dosExistObjectI18nCA[$doI18nCA->getId()] = $doI18nCA;
}
$dosDataObjectsFoto = $em->getRepository(DorigenFoto::class)->findAll();
foreach( $dosDataObjectsFoto as $doFoto )
{
$dosExistObjectFoto[$doFoto->getDorigen()->getId()] = isset($dosExistObjectFoto[$doFoto->getDorigen()->getId()]) ? $dosExistObjectFoto[$doFoto->getDorigen()->getId()] : [];
$dosExistObjectFoto[$doFoto->getDorigen()->getId()][$doFoto->getFoto()] = $doFoto;
}
$sheetData = $spreadsheet->getSheet(1)->toArray();
$i=4;
unset($sheetData[0]);
unset($sheetData[1]);
unset($sheetData[2]);
foreach( $sheetData as $t )
{
if($t[0] ){
$dorigen = new Dorigen();
$dorigenI18n = new DorigenI18n();
if(isset($dosExist[$t[5]])){
$dorigen = $dosExistObject[$dosExist[$t[5]]['id']];
$dorigenI18n = $dosExistObjectI18n[$dosExist[$t[5]]['idI18n']];
} else {
$token = $generator->generate($tokenLength);
$dorigen->setHashId($token);
}
$logo = 'uploads/dorigen/img_do_'.$dorigen->getId().'_logo.png';
if($t[6]){
$url = $t[6];
//dd($this->curl_get_contents($url));
file_put_contents($logo, $this->curl_get_contents($url));
} else {
if(file_exists($logo)){
unlink($logo);
}
$logo = '';
}
$dorigen->setEstado(1);
$dorigen->setLogo($logo);
$dorigen->setUrlWeb($t[2] ? $t[2] : '');
$dorigen->setUrlInstagram($t[3] ? $t[3] : '');
$dorigen->setFechaCreacion(new DateTime());
$em->persist($dorigen);
$em->flush();
/* imagenes 10,11,12,13 */
for($x = 10; $x<=13;$x++){
$img = 'uploads/dorigen/img_do_'.$dorigen->getId().'_'.($x-9).'.jpg';
if($t[$x]){
$url = $t[$x];
file_put_contents($img, $this->curl_get_contents($url));
if(!isset($dosExistObjectFoto[$dorigen->getId()][$img])){
$foto = new DorigenFoto();
$foto->setDorigen($dorigen);
$foto->setFoto($img);
$foto->setDestacada($x-9 == 1 ? 1 : 0);
$foto->setFechaCreacion(new DateTime());
$em->persist($foto);
}
} else {
if(file_exists($img)){
unlink($img);
}
if(isset($dosExistObjectFoto[$dorigen->getId()][$img])){
$em->remove($dosExistObjectFoto[$dorigen->getId()][$img]);
}
}
}
$dorigenI18n->setDorigen($dorigen);
$dorigenI18n->setIdioma($langData);
$dorigenI18n->setNombre($t[0]);
$dorigenI18n->setDescripcion($t[1] ? $t[1] : '');
$dorigenI18n->setUrlSemantica($t[5] ? $t[5] : '');
$dorigenI18n->setFechaCreacion(new DateTime());
$em->persist($dorigenI18n);
$dorigenI18nCA = new DorigenI18n();
if(isset($dosExistCA[$t[5]])){
$dorigenI18nCA = $dosExistObjectI18nCA[$dosExistCA[$t[5]]['idI18n']];
}
$dorigenI18nCA->setDorigen($dorigen);
$dorigenI18nCA->setIdioma($langDataCA);
$dorigenI18nCA->setNombre($t[0]);
$dorigenI18nCA->setDescripcion($t[1] ? $t[1] : '');
$dorigenI18nCA->setUrlSemantica($t[5] ? $t[5] : '');
$dorigenI18nCA->setFechaCreacion(new DateTime());
$em->persist($dorigenI18nCA);
$dos[] = [
"i" => $i,
't0'=> $dorigenI18n->getNombre(),
];
}
$i++;
}
// print_r($dos);
// die();
}
/* bodegas */
$bodegas = [];
$bodegasExist = [];
$bodegasExistCA = [];
$bodegasExistObject = [];
$bodegasData = $em->getRepository(Bodega::class)->findAllImport($langData->getId());
foreach( $bodegasData as $b )
{
$bodegasExist[$b['url']] = ['id' => $b['id'], 'idI18n' => $b['idI18n']];
}
$bodegasDataCA = $em->getRepository(Bodega::class)->findAllImport($langDataCA->getId());
foreach( $bodegasDataCA as $bCA )
{
$bodegasExistCA[$bCA['url']] = ['id' => $bCA['id'], 'idI18n' => $bCA['idI18n']];
}
$bodegasDataObjects = $em->getRepository(Bodega::class)->findAll();
foreach( $bodegasDataObjects as $bo )
{
$bodegasExistObject[$bo->getId()] = $bo;
}
if($tipo_import == 'bodega'){
$bodegasExistObjectI18n = [];
$bodegasExistObjectI18nCA = [];
$bodegasExistObjectFoto = [];
$bodegasDoExistObject = [];
$bodegasDataObjectsI18n = $em->getRepository(BodegaI18n::class)->findBy(['idioma' => $langData->getId()]);
foreach( $bodegasDataObjectsI18n as $boI18n )
{
$bodegasExistObjectI18n[$boI18n->getId()] = $boI18n;
}
$bodegasDataObjectsI18nCA = $em->getRepository(BodegaI18n::class)->findBy(['idioma' => $langDataCA->getId()]);
foreach( $bodegasDataObjectsI18nCA as $boI18nCA )
{
$bodegasExistObjectI18nCA[$boI18nCA->getId()] = $boI18nCA;
}
$bodegasDataObjectsFoto = $em->getRepository(BodegaFoto::class)->findAll();
foreach( $bodegasDataObjectsFoto as $boFoto )
{
$bodegasExistObjectFoto[$boFoto->getBodega()->getId()] = [];
$bodegasExistObjectFoto[$boFoto->getBodega()->getId()][$boFoto->getFoto()] = $boFoto;
}
$bodegasDataObjectsDO = $em->getRepository(RelDorigenBodega::class)->findAll();
foreach( $bodegasDataObjectsDO as $dob )
{
$bodegasDoExistObject[$dob->getBodega()->getId()] = isset($bodegasDoExistObject[$dob->getBodega()->getId()]) ? $bodegasDoExistObject[$dob->getBodega()->getId()] : [];
$bodegasDoExistObject[$dob->getBodega()->getId()][$dob->getDorigen()->getId()] = $dob;
}
$sheetData = $spreadsheet->getSheet(2)->toArray();
$i=4;
unset($sheetData[0]);
unset($sheetData[1]);
unset($sheetData[2]);
foreach( $sheetData as $t )
{
if($t[0] ){
$bodega = new Bodega();
$bodegaI18n = new BodegaI18n();
$bodegaI18nCA = new BodegaI18n();
if(isset($bodegasExist[$t[2]])){
$bodega = $bodegasExistObject[$bodegasExist[$t[2]]['id']];
$bodegaI18n = $bodegasExistObjectI18n[$bodegasExist[$t[2]]['idI18n']];
} else {
$token = $generator->generate($tokenLength);
$bodega->setHashId($token);
}
$logo = 'uploads/bodega/img_bodega_'.$bodega->getId().'_logo.png';
if($t[14]){
$url = $t[14];
file_put_contents($logo, $this->curl_get_contents($url));
} else {
if(file_exists($logo)){
unlink($logo);
}
$logo = '';
}
$bodega->setLogo($logo);
$dorigen = null;
if(isset($dosExist[$t[0]])){
$dorigen = $dosExistObject[$dosExist[$t[0]]['id']];
} else {
echo "no existe la do";
print_r($t[0]);
die();
}
$bodega->setUrlWeb($t[3] ? $t[3] : '');
$bodega->setEmailReserva($t[4] ? $t[4] : '');
$bodega->setDireccion($t[7] ? $t[7] : '');
$bodega->setCodigoPostal($t[8] ? $t[8] : '');
$bodega->setPoblacion($t[9] ? $t[9] : '');
$bodega->setTelefonoContacto($t[10] ? $t[10] : '');
$bodega->setUrlInstagram($t[11] ? $t[11] : '');
$bodega->setFechaCreacion(new DateTime());
// mapa 13
$googleMaps = $t[13];
$latitud=null;
$longitud=null;
if($googleMaps){
$googleMaps = substr($googleMaps, strpos($googleMaps, '@')+1);
$googleMaps = substr($googleMaps, 0, strpos($googleMaps, '/data'));
$arrayMaps = explode(",", $googleMaps);
$latitud = $arrayMaps[0];
$longitud = $arrayMaps[1];
}
$bodega->setLatitud($latitud);
$bodega->setLongitud($longitud);
$em->persist($bodega);
$em->flush();
//$bodega->setDorigen($dorigenI18n->getDorigen());
$dorigenBodega = new RelDorigenBodega();
if(isset($bodegasDoExistObject[$bodega->getId()][$dorigen->getId()])){
$dorigenBodega = $bodegasDoExistObject[$bodega->getId()][$dorigen->getId()];
}
$dorigenBodega->setBodega($bodega);
$dorigenBodega->setDorigen($dorigen);
$dorigenBodega->setFechaCreacion(new DateTime());
$em->persist($dorigenBodega);
// print_r($bodega->getId());
// die();
/* imagenes 17,18,19,20 */
for($x = 17; $x<=20;$x++){
$img = 'uploads/bodega/img_bodega_'.$bodega->getId().'_'.($x-16).'.jpg';
if($t[$x]){
$url = $t[$x];
file_put_contents($img, $this->curl_get_contents($url));
if(!isset($bodegasExistObjectFoto[$bodega->getId()][$img])){
$foto = new BodegaFoto();
$foto->setBodega($bodega);
$foto->setFoto($img);
$foto->setDestacada($x-16 == 1 ? 1 : 0);
$foto->setFechaCreacion(new DateTime());
$em->persist($foto);
}
} else {
if(file_exists($img)){
unlink($img);
}
if(isset($bodegasExistObjectFoto[$bodega->getId()][$img])){
$em->remove($bodegasExistObjectFoto[$bodega->getId()][$img]);
}
}
}
$bodegaI18n->setBodega($bodega);
$bodegaI18n->setIdioma($langData);
$bodegaI18n->setNombre($t[1] ? $t[1] : '');
$bodegaI18n->setDescripcion($t[12] ? $t[12] : '');
$bodegaI18n->setUrlSemantica($t[2] ? $t[2] : '');
$bodegaI18n->setFechaCreacion(new DateTime());
$em->persist($bodegaI18n);
if(isset($bodegasExistCA[$t[2]])){
$bodegaI18nCA = $bodegasExistObjectI18nCA[$bodegasExistCA[$t[2]]['idI18n']];
}
$bodegaI18nCA->setBodega($bodega);
$bodegaI18nCA->setIdioma($langDataCA);
$bodegaI18nCA->setNombre($t[1] ? $t[1] : '');
$bodegaI18nCA->setDescripcion($t[12] ? $t[12] : '');
$bodegaI18nCA->setUrlSemantica($t[2] ? $t[2] : '');
$bodegaI18nCA->setFechaCreacion(new DateTime());
$em->persist($bodegaI18nCA);
$bodegas[] = [
"i" => $i,
't0'=> $bodegaI18n->getNombre(),
];
}
$i++;
}
// print_r($bodegas);
// die();
}
/* actividades */
$actividades = [];
if($tipo_import == 'actividad'){
$actividadesExist = [];
$actividadesExistObject = [];
$actividadesExistObjectI18n = [];
$actividadesExistObjectFoto = [];
$actividadesData = $em->getRepository(Actividad::class)->findAllImport($langData->getId());
foreach( $actividadesData as $a )
{
$actividadesExist[$a['importRow']] = ['id' => $a['id'], 'idI18n' => $a['idI18n']];
}
$actividadesDataObjects = $em->getRepository(Actividad::class)->findAll();
foreach( $actividadesDataObjects as $ao )
{
$actividadesExistObject[$ao->getId()] = $ao;
}
$actividadesDataObjectsI18n = $em->getRepository(ActividadI18n::class)->findBy(['idioma' => $langData->getId()]);
foreach( $actividadesDataObjectsI18n as $aoI18n )
{
$actividadesExistObjectI18n[$aoI18n->getId()] = $aoI18n;
}
$actividadesDataObjectsFoto = $em->getRepository(ActividadFoto::class)->findAll();
foreach( $actividadesDataObjectsFoto as $aoFoto )
{
$actividadesExistObjectFoto[$aoFoto->getActividad()->getId()] = isset($actividadesExistObjectFoto[$aoFoto->getActividad()->getId()]) ? $actividadesExistObjectFoto[$aoFoto->getActividad()->getId()] : [];
$actividadesExistObjectFoto[$aoFoto->getActividad()->getId()][$aoFoto->getFoto()] = $aoFoto;
}
$tiposI18nData = $em->getRepository(TipoI18n::class)->findAll();
$tipos = [];
foreach($tiposI18nData as $t){
$tipos[$t->getUrlSemantica()] = $t->getTipo();
}
$relATData = $em->getRepository(RelActividadTipo::class)->findAll();
$relAT = [];
foreach($relATData as $rat){
$relAT[$rat->getActividad()->getId()] = [];
$relAT[$rat->getActividad()->getId()][$rat->getTipo()->getId()] = $rat;
}
$sheetData = $spreadsheet->getSheet(3)->toArray();
$i=4;
unset($sheetData[0]);
unset($sheetData[1]);
unset($sheetData[2]);
foreach( $sheetData as $t )
{
if($t[0] ){
$actividad = new Actividad();
$actividadI18n = new ActividadI18n();
if(isset($actividadesExist[$i])){
$actividad = $actividadesExistObject[$actividadesExist[$i]['id']];
$actividadI18n = $actividadesExistObjectI18n[$actividadesExist[$i]['idI18n']];
} else {
$token = $generator->generate($tokenLength);
$actividad->setHashId($token);
}
$bodega = null;
if(isset($bodegasExist[$t[0]])){
$bodega = $bodegasExistObject[$bodegasExist[$t[0]]['id']];
} else {
echo "no existe la bodega";
print_r($t[0]);
die();
}
$actividad->setBodega($bodega);
$actividad->setDireccion($bodega->getDireccion());
$actividad->setLatitud($bodega->getLatitud());
$actividad->setLongitud($bodega->getLongitud());
$m = $em->getRepository(Municipio::class)->findOneByNombre($bodega->getPoblacion());
if($m){
$actividad->setMunicipio($m);
}
$dorigen = null;
if(isset($dosExist[$t[1]])){
$dorigen = $dosExistObject[$dosExist[$t[1]]['id']];
} else {
echo "no existe la do";
print_r($t[1]);
die();
}
$actividad->setDorigen($dorigen);
$actividad->setImportRow($i);
$actividad->setDuracion($t[4] ? $t[4] : '');
$actividad->setFechaCreacion(new DateTime());
$em->persist($actividad);
$em->flush();
// TODO: PRECIOS INCORRECTOS
// $precio = $em->getRepository(Precio::class)->findOneBy(['actividad' => $actividad->getId()]);
// if(!$precio){
// $precio = new Precio();
// $precio->setActividad($actividad);
// $precio->setFechaCreacion(new DateTime());
// }
// $precio->setPrecio($t[5] ? $t[5] : 0);
// $em->persist($precio);
/* imagenes 17,18,19,20 */
for($x = 17; $x<=20;$x++){
$img = 'uploads/actividad/img_actividad_'.$actividad->getId().'_'.($x-16).'.jpg';
if($t[$x]){
$url = $t[$x];
file_put_contents($img, $this->curl_get_contents($url));
if(!isset($actividadesExistObjectFoto[$actividad->getId()][$img])){
$foto = new ActividadFoto();
$foto->setActividad($actividad);
$foto->setFoto($img);
$foto->setDestacada($x-16 == 1 ? 1 : 0);
$foto->setFechaCreacion(new DateTime());
$em->persist($foto);
}
} else {
if(file_exists($img)){
unlink($img);
}
if(isset($actividadesExistObjectFoto[$actividad->getId()][$img])){
$em->remove($actividadesExistObjectFoto[$actividad->getId()][$img]);
}
}
}
$actividadI18n->setActividad($actividad);
$actividadI18n->setIdioma($langData);
$actividadI18n->setNombre($t[2] ? $t[2] : '');
$actividadI18n->setDescripcion($t[3] ? $t[3] : '');
$actividadI18n->setIncluye($t[7] ? $t[7] : '');
$actividadI18n->setNoIncluye($t[8] ? $t[8] : '');
$actividadI18n->setInfoAdicional($t[9] ? $t[9] : '');
//$actividadI18n->setUrlSemantica(''); // crear
if($t[2]){
$actividadI18n->setUrlSemantica($this->semanticUrl($t[2]));
// echo $t[2];
// dd($this->semanticUrl($t[2]));
}
$actividadI18n->setFechaCreacion(new DateTime());
$em->persist($actividadI18n);
if($t[13] && isset($tipos[$t[13]])){
if(!isset($relAT[$actividad->getId()][$t[13]])){
$newRAT = new RelActividadTipo();
$newRAT->setActividad($actividad);
$newRAT->setTipo($tipos[$t[13]]);
$newRAT->setFechaCreacion(new DateTime());
$em->persist($newRAT);
}
}
$actividades[] = [
"i" => $i,
't0'=> $actividadI18n->getNombre(),
];
// FALTAN DIAS
// FALTAN HORAS
// FALTAN IDIOMAS
}
$i++;
}
print_r($actividades);
die();
}
$em->flush();
// Return JSON data
$response = new JsonResponse();
$response->setStatusCode($responseCode);
$response->setData([
"importadas" => $actividades,
]);
return $response;
}
public function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public function semanticUrl($text){
$url=$text;
$url = $this->stripAccents($url);
$url = (str_replace('&', "", $url));
$url = (str_replace('"', "_", $url));
$url = (str_replace("'", "_", $url));
$url = (str_replace(":", "", $url));
$url = (str_replace(".", "", $url));
$url = (str_replace(",", "", $url));
$url = (str_replace(";", "", $url));
$url = (str_replace("`", "_", $url));
$url = strtolower(str_replace(" ", "_", $url));
$url = preg_replace('/[^A-Za-z0-9\_]/', '', $url);
return $url;
}
public function stripAccents($str) {
$a = array('Ñ','ñ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
$b = array('N','n','A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
return str_replace($a, $b, $str);
}
}