<?php
namespace App\Controller\Webservice;
use App\Entity\Category;
use App\Entity\User;
use App\Entity\EventReport;
use App\Entity\BlogReport;
use App\Entity\Appointment;
use App\Entity\NotificationReport;
use App\Entity\VoiceExercise;
use App\Repository\UserRepository;
use App\Repository\UserRoleRepository;
use App\Repository\BlogRepository;
use App\Repository\BlogReportRepository;
use App\Repository\OrganizationRepository;
use App\Repository\HomeSettingRepository;
use App\Repository\AppointmentStatusRepository;
use App\Repository\AppointmentRepository;
use App\Repository\NotificationReportRepository;
use App\Repository\EventListRepository;
use App\Repository\EventReportRepository;
use App\Repository\NotificationRepository;
use App\Repository\NotificationPushReportRepository;
use App\Repository\BibleListRepository;
use App\Repository\ConferenceCategoryRepository;
use App\Repository\BlogCategoryRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; // @dth: to encode the pass
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\KernelInterface;
use App\Service\HelperService;
/**
* @Route("ws")
*/
class WebserviceController extends AbstractController
{
private $passwordEncoder;
private $environment;
public function __construct(UserPasswordEncoderInterface $passwordEncoder, KernelInterface $kernel)
{
$this->passwordEncoder = $passwordEncoder;
$this->environment = $kernel->getEnvironment();
}
/**
* @Route("/check_user", name="ws_login", methods={"GET", "POST"})
*/
public function checkUser(UserRepository $userRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$user = $data->user;
$pass = $data->pwd;
$token = $data->token;
$paths = $helperService->getPaths();
$userObj = $userRepository->findOneBy(['email' => $user]);
if($userObj)
{
if(!$this->passwordEncoder->isPasswordValid($userObj, $pass))
{
return new JsonResponse(array('status' => 'invalid'));
} else {
$data = array(
'id' => $userObj->getId(),
'name' => $userObj->getFirstName()." ".$userObj->getLastName(),
'first_name' => $userObj->getFirstName(),
'last_name' => $userObj->getLastName(),
'email' => $userObj->getEmail(),
'status' => $userObj->getStatus(),
'role_id' => $userObj->getUserRole()->getId(),
'token' => md5($userObj->getId()),
'organization_id' => $userObj->getOrganization()->getOrganizationId(),
'organization_bkg' => $paths['uploads_path']."/".$userObj->getOrganization()->getBkgImage(),
'organization_logo' => $paths['uploads_path']."/".$userObj->getOrganization()->getLogoPath(),
'organization_name' => $userObj->getOrganization()->getName(),
'has_help' => $userObj->getOrganization()->getHasHelp()
);
$userObj->setToken($token);
$entityManager->persist($userObj);
$entityManager->flush();
return new JsonResponse(array('status' => 'success', 'data' => $data ));
}
}
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/check_activation", name="ws_check_activation", methods={"GET", "POST"})
*/
public function checkActivation(UserRepository $userRepository, Request $request, EntityManagerInterface $entityManager, UserRoleRepository $userRoleRepository,OrganizationRepository $organizationRepository, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$user = $data->token;
$userObj = $userRepository->findOneBy(['id' => $user->id]);
if($userObj)
{
$paths = $helperService->getPaths();
$data = array(
'id' => $userObj->getId(),
'name' => $userObj->getFirstName()." ".$userObj->getLastName(),
'first_name' => $userObj->getFirstName(),
'last_name' => $userObj->getLastName(),
'email' => $userObj->getEmail(),
'status' => $userObj->getStatus(),
'role_id' => $userObj->getUserRole()->getId(),
'token' => md5($userObj->getId()),
'organization_id' => $userObj->getOrganization()->getOrganizationId(),
'organization_bkg' => $paths['uploads_path']."/".$userObj->getOrganization()->getBkgImage(),
'organization_logo' => $paths['uploads_path']."/".$userObj->getOrganization()->getLogoPath(),
'organization_name' => $userObj->getOrganization()->getName(),
'has_help' => $userObj->getOrganization()->getHasHelp()
);
return new JsonResponse(array('status' => 'success', 'data' => $data ));
}
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/register_user", name="ws_register", methods={"GET", "POST"})
*/
public function registerUser(UserRepository $userRepository, Request $request, EntityManagerInterface $entityManager, UserRoleRepository $userRoleRepository,OrganizationRepository $organizationRepository, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$user = $data->register;
$paths = $helperService->getPaths();
$userObj = $userRepository->findOneBy(['email' => $user->email, 'status'=>'ACTIVO']);
if($userObj)
{
return new JsonResponse(array('status' => 'duplicate'));
} else {
$userRole = $userRoleRepository->findOneBy(['id'=>2]);
$orgObj = $organizationRepository->findOneBy(['organizationId' => $user->organization_id]);
$register = new User();
$encoded = $this->passwordEncoder->encodePassword($register, $user->password);
$register->setFirstName($user->first_name);
$register->setLastName($user->last_name);
$register->setEmail($user->email);
$register->setGender($user->gender);
$register->setPassword($encoded);
$register->setOrganization($orgObj);
$register->setPhonePrimary($user->phone);
$register->setStatus("ESPERANDO");
$register->setBirthdate(substr($user->birthdate,0,10));
$register->setUserRole($userRole);
$entityManager->persist($register);
$entityManager->flush();
return new JsonResponse(array('status' => 'success'));
}
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/download-bible-list", name="ws_download_bible_list", methods={"GET", "POST"})
*/
public function downloadBibleList(BibleListRepository $bibleListRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$data = json_decode(file_get_contents("php://input"));
if(true)
{
$token = "aa";//$data->token;
$arrayEsp = [];
$arrayEng = [];
$arrayOther = [];
$list = $bibleListRepository->findBy(["is_active" => 1]);
foreach($list as $item)
{
$testaments = [];
foreach(explode(",",$item->getBibleGroup()) as $group)
{
if($group == 'OT')
{
$testaments[] = "Antiguo Testamento";
}
if($group == 'NT')
{
$testaments[] = "Nuevo Testamento";
}
if($group == 'AP')
{
$testaments[] = "Libros Apócrifos";
}
}
if($item->getLanguageName() == 'Spanish')
{
$language = 'Español';
} else if($item->getLanguageName() == 'English')
{
$language = 'Inglés';
} else {
$language = $item->getLanguageName();
}
if($item->getLanguageName() == 'Spanish')
{
$arrayEsp[] = [
'bible_list_id' => $item->getBibleListId(),
'bible_code' => $item->getBibleCode(),
'name' => $item->getName(),
'testaments' => $testaments,
'language' => $language,
'filepath' => $item->getFilePath(),
'is_visible' => 1
];
} else if($item->getLanguageName() == 'English')
{
$arrayEng[] = [
'bible_list_id' => $item->getBibleListId(),
'bible_code' => $item->getBibleCode(),
'name' => $item->getName(),
'testaments' => $testaments,
'language' => $language,
'filepath' => $item->getFilePath(),
'is_visible' => 1
];
} else {
$arrayOther[] = [
'bible_list_id' => $item->getBibleListId(),
'bible_code' => $item->getBibleCode(),
'name' => $item->getName(),
'testaments' => $testaments,
'language' => $language,
'filepath' => $item->getFilePath(),
'is_visible' => 1
];
}
}
return new JsonResponse(array('status' => 'success', 'spanish' => $arrayEsp, 'english' => $arrayEng, 'other' => $arrayOther));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/download-bible", name="ws_download_bible", methods={"GET", "POST"})
*/
public function downloadBible(BibleListRepository $bibleListRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$paths = $helperService->getPaths();
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$bibleId = $data->bid;
if($bibleId)
{
//$token = $data->token;
//$category = $data->category;
$array = [];
$item = $bibleListRepository->findOneBy(["bibleListId" => $bibleId]);
if($item)
{
$content = file_get_contents($paths['bibles_path'].$item->getFilePath());
$array = [
'path' => $paths['bibles_path'].$item->getFilePath(),
'content' => $content,
'filename' => $item->getFilePath()
];
return new JsonResponse(array('status' => 'success', 'data' => $array));
}
}
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/get-blogs", name="ws_get_blogs", methods={"GET", "POST"})
*/
public function getBlogs(BlogRepository $blogRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$oid = $data->oid;
$paths = $helperService->getPaths();
$array = [];
$blogs = $blogRepository->findBy(["is_active" => 1, "is_publish" => 1, "Organization" => $oid], ["created_at" => "DESC"], 5);
foreach($blogs as $blog)
{
$automaticVoice = strip_tags($blog->getLargeContent());
$automaticVoice = str_replace(" ", " ", $automaticVoice);
$organizationId = $blog->getOrganization()->getOrganizationId();
/*
es-es-x-eee-local
es-es-x-eef-local
es-es-x-eea-local
es-es-x-eec-network
es-es-x-eed-network
es-es-x-eea-network
es-es-x-eed-local
es-es-x-eec-local
es-ES-language
es-US-language
es-us-x-esd-network
es-us-x-esf-network
es-us-x-esc-network
es-us-x-esc-local
es-us-x-esf-local
es-us-x-esd-local*/
$filePath = str_replace("?dl=0", "?raw=1", $blog->getFilePath());
$array[] = [
'blog_id' => $blog->getBlogId(),
'title' => $blog->getName(),
'short_content' => $blog->getShortContent(),
'large_content' => $blog->getLargeContent(),
'file_path' => $filePath,
'file_extension' => $blog->getFileExtension(),
'striped_content' => $automaticVoice,
'bkg_image' => $paths['uploads_path']."/".$organizationId."/".$blog->getBkgImage(),
'category_name' => $blog->getBlogCategory()->getName(),
'created_at' => $blog->getCreatedAt()->format("Y/m/d"),
'created_by' => $blog->getCreatedBy()->getFirstName()." ".$blog->getCreatedBy()->getLastName(),
'voice_options' => ["identifier" =>'es-us-x-esd-network', "rate" => 1.04, "pitch" => 0.99, "cancel" => true]
];
}
return new JsonResponse(array('status' => 'success', 'data' => $array));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/get-organization-info", name="ws_get_organization_info", methods={"GET", "POST"})
*/
public function getOrganizationInfo(UserRepository $userRepository, OrganizationRepository $organizationRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService, HomeSettingRepository $homeSettingRepository): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$organizationId = $data->oid;
$token = $data->token;
$object = $organizationRepository->findOneBy(['organizationId' => $organizationId]);
if($object)
{
$userObj = $userRepository->findOneBy(array('id' => $token->id));
$paths = $helperService->getPaths();
$bible_bkg = $paths['assets_path']."img/bkg_bible.jpg";
$blog_bkg = $paths['assets_path']."img/bkg_blog.jpg";
$event_bkg = $paths['assets_path']."img/bkg_event.jpg";
$help_bkg = $paths['assets_path']."img/bkg_help.jpg";
$design = 1;
$homeSetting = $homeSettingRepository->findOneBy(['Organization' => $organizationId]);
if($homeSetting)
{
if(strlen($homeSetting->getBibleBkg())>0)
{
$bible_bkg = $paths['uploads_path'].$organizationId."/".$homeSetting->getBibleBkg();
}
if(strlen($homeSetting->getBlogBkg())>0)
{
$blog_bkg = $paths['uploads_path'].$organizationId."/".$homeSetting->getBlogBkg();
}
if(strlen($homeSetting->getEventBkg())>0)
{
$event_bkg = $paths['uploads_path'].$organizationId."/".$homeSetting->getEventBkg();
}
if(strlen($homeSetting->getHelpBkg())>0)
{
$help_bkg = $paths['uploads_path'].$organizationId."/".$homeSetting->getHelpBkg();
}
if($homeSetting->getHomeTemplate())
{
$design = $homeSetting->getHomeTemplate()->getHomeTemplateId();
}
}
$has_help = 0;
$bible_col = 12;
if($object->getHasHelp() == 1)
{
$has_help = 1;
$bible_col = 6;
}
$array = [
'name' => $object->getName(),
'about_us' => $object->getAboutUs(),
'logo_path' => $paths['uploads_path'].$object->getLogoPath(),
'bkg_image' => $paths['uploads_path'].$object->getBkgImage(),
'bible_bkg' => $bible_bkg,
'blog_bkg' => $blog_bkg,
'event_bkg' => $event_bkg,
'help_bkg' => $help_bkg,
'has_help' => $has_help,
'bible_col' => $bible_col,
'design' => $design,
'user_status' => $userObj->getStatus()
];
}
return new JsonResponse(array('status' => 'success', 'data' => $array));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/get-blog-category", name="ws_get_blog_category", methods={"GET", "POST"})
*/
public function getBlogCategories(BlogCategoryRepository $blogCategoryRepository, BlogRepository $blogRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$user = $data->token;
$paths = $helperService->getPaths();
$array = [];
$blogsCategory = $blogCategoryRepository->findBy([
"is_active" => 1,
"Organization" => $user->organization_id,
], ["name" => "ASC"]);
foreach($blogsCategory as $object)
{
$arrayBlogs = [];
$blogs = $blogRepository->findBy([
"BlogCategory" => $object->getBlogCategoryId(),
"is_active" => 1,
"is_publish" => 1
], ["created_at" => "DESC"]);
foreach($blogs as $blog)
{
$organizationId = $blog->getOrganization()->getOrganizationId();
$filePath = str_replace("?dl=0", "?raw=1", $blog->getFilePath());
$arrayBlogs[] = [
'blog_id' => $blog->getBlogId(),
'title' => $blog->getName(),
'short_content' => $blog->getShortContent(),
'large_content' => $blog->getLargeContent(),
'file_path' => $filePath,
'file_extension' => $blog->getFileExtension(),
'bkg_image' => $paths['uploads_path']."/".$organizationId."/".$blog->getBkgImage(),
'category_name' => $blog->getBlogCategory()->getName(),
'created_at' => $blog->getCreatedAt()->format("Y/m/d"),
'created_by' => $blog->getCreatedBy()->getFirstName()." ".$blog->getCreatedBy()->getLastName(),
'visible' => 1
];
}
$array[] = [
'title' => $object->getName(),
'description' => $object->getDescription(),
'blogs' => $arrayBlogs,
'visible' => 1
];
}
return new JsonResponse(array('status' => 'success', 'data' => $array));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/get-schedule", name="/ws_get_schedule")
*/
public function scheduleUserAction(UserRepository $userRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$em = $this->getDoctrine()->getManager();
$data = json_decode(file_get_contents("php://input"));
$schedule = array();
if($data)
{
$professional_id = $data->professionalId;
$category_id = $data->categoryId;
$date_to_search = $data->selectedDate;
$organizationId = $data->oid;
//$professional_id = 40;
//$category_id = 1;//$data->categoryId;
//$date_to_search = '2022-01-28';//$data->selectedDate;
$scheduleRaw = $userRepository->scheduleUser($professional_id,$category_id,$date_to_search, $organizationId);
//if($schedule == 'error')
//{
//} else {
$schedule = $scheduleRaw;
//}
}
return new JsonResponse(array('data' => $schedule));
}
/**
* @Route("/register-schedule", name="/ws_register_schedule")
*/
public function registerAction(UserRepository $userRepository, ConferenceCategoryRepository $conferenceCategoryRepository, AppointmentStatusRepository $appointmentStatusRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$token = $data->token;
$professionalId = $data->professionalId;
$category = $data->category;
$schedule = $data->schedule;
$user = $userRepository->findOneBy(array("status" => 'ACTIVO', 'id' => $token->id));
$professional = $userRepository->findOneBy(array("status" => 'ACTIVO', 'id' => $professionalId));
$categoryObj = $conferenceCategoryRepository->findOneBy(array("is_active" => 1, "conferenceCategoryId" => $category));
$status = $appointmentStatusRepository->findOneBy(array("appointmentStatusId" => 1));
$appointment = new Appointment();
$appointment->setOrganization($user->getOrganization());
$appointment->setConferenceCategory($categoryObj);
$appointment->setUser($professional);
$appointment->setAppointmentConsumeMinutes($categoryObj->getAppointmentConsumeMinutes());
$appointment->setAppointmentStatus($status);
$appointment->setScheduledAt($schedule);
$appointment->setCreatedBy($user);
$appointment->setCreatedAt(new \DateTime());
$entityManager->persist($appointment);
$entityManager->flush();
if($appointment->getAppointmentId())
{
return new JsonResponse(array('status' => "success", 'appointment' => $appointment->getAppointmentId()));
} else {
return new JsonResponse(array('status' => "error"));
}
}
return new JsonResponse(array('status' => "error"));
}
/**
* @Route("/get-conference-categories", name="ws_get_conference_categories", methods={"GET", "POST"})
*/
public function getConferenceCategories(ConferenceCategoryRepository $conferenceCategoryRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$user = $data->token;
$paths = $helperService->getPaths();
$array = [];
$list = $conferenceCategoryRepository->findBy([
"is_active" => 1,
"is_publish" => 1,
"Organization" => $user->organization_id
], ["created_at" => "DESC"], 5);
foreach($list as $item)
{
$array[] = [
'category_id' => $item->getConferenceCategoryId(),
'title' => $item->getName(),
'description' => $item->getDescription(),
'bkg_image' => $paths['uploads_path']."/".$item->getBackgroundPath(),
'created_at' => $item->getCreatedAt()->format("Y/m/d"),
'created_by' => $item->getCreatedBy()->getFirstName()." ".$item->getCreatedBy()->getLastName()
];
}
return new JsonResponse(array('status' => 'success', 'data' => $array));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/report-bulletin", name="ws_report_bulletin", methods={"GET", "POST"})
*/
public function reportBulletin(UserRepository $userRepository, NotificationRepository $notificationRepository, NotificationReportRepository $notificationReportRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
if($notificationReportRepository->findOneBy(['user' => $data->token->id, 'notification' => $data->notification_id]))
{
} else {
$notificationObj = $notificationRepository->findOneBy(["notificationId" => $data->notification_id]);
$userObj = $userRepository->findOneBy(["id" => $data->token->id]);
$obj = new NotificationReport();
$obj->setUser($userObj);
$obj->setNotification($notificationObj);
$obj->setCreatedAt(new \DateTime());
$entityManager->persist($obj);
$entityManager->flush();
}
return new JsonResponse(array('status' => 'success'));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/report-event", name="ws_report_event", methods={"GET", "POST"})
*/
public function reportEvent(UserRepository $userRepository, EventListRepository $eventListRepository, EventReportRepository $eventReportRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
if($eventReportRepository->findOneBy(['user' => $data->token->id, 'eventList' => $data->event_id]))
{
} else {
$eventObj = $eventListRepository->findOneBy(["eventListId" => $data->event_id]);
$userObj = $userRepository->findOneBy(["id" => $data->token->id]);
$obj = new EventReport();
$obj->setUser($userObj);
$obj->setEventList($eventObj);
$obj->setCreatedAt(new \DateTime());
$entityManager->persist($obj);
$entityManager->flush();
}
return new JsonResponse(array('status' => 'success'));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/cancel-appointment", name="ws_cancel_appointment", methods={"GET", "POST"})
*/
public function cancelAppointment(UserRepository $userRepository, AppointmentRepository $appointmentRepository, AppointmentStatusRepository $appointmentStatusRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$obj = $appointmentRepository->findOneBy(['appointmentId' => $data->appointment_id]);
if($obj)
{
$status = $appointmentStatusRepository->findOneBy(['appointmentStatusId' => 3]);
$user = $userRepository->findOneBy(array("status" => 'ACTIVO', 'id' => $data->token->id));
$obj->setAppointmentStatus($status);
$obj->setUpdatedBy($user);
$obj->setUpdatedAt(new \DateTime());
$entityManager->persist($obj);
$entityManager->flush();
return new JsonResponse(array('status' => 'success'));
} else {
return new JsonResponse(array('status' => 'invalid'));
}
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/report-blog", name="ws_report_blog", methods={"GET", "POST"})
*/
public function reportBlog(UserRepository $userRepository, BlogRepository $blogRepository, BlogReportRepository $blogReportRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
if($blogReportRepository->findOneBy(['user' => $data->token->id, 'blog' => $data->blog_id]))
{
} else {
$blogObj = $blogRepository->findOneBy(["blogId" => $data->blog_id]);
$userObj = $userRepository->findOneBy(["id" => $data->token->id]);
$obj = new BlogReport();
$obj->setUser($userObj);
$obj->setBlog($blogObj);
$obj->setCreatedAt(new \DateTime());
$entityManager->persist($obj);
$entityManager->flush();
}
return new JsonResponse(array('status' => 'success'));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/push-test", name="ws_push_test", methods={"GET", "POST"})
*/
public function pushTest(HelperService $helperService): Response
{
return new JsonResponse(['status' => 'false']);
$serviceAccountFile = $this->getParameter('kernel.project_dir') . '/src/Service/n0bd2-db37748d66.json';
// Obtén el token de acceso generando manualmente un JWT.
$accessToken = $this->getAccessToken($serviceAccountFile);
// Lee el archivo de credenciales para obtener el project_id.
$credentials = json_decode(file_get_contents($serviceAccountFile), true);
$projectId = $credentials['project_id'];
// Construye el mensaje FCM. Se utiliza el token del dispositivo al que enviar la notificación.
$deviceToken = "dDSaIz4TRfSmSmR5IhzoVD:APA91bG8ruNpuGqjUpyxkBlJhcIU7gHteHBi2nmEhqxu-ai9VigFRqwwcL9H_HgvYmlBWWib088YGWQiIgNclzEP-VgTLYgGIaq-uQKDxGVjGrfTztvbSwQ";
$message = [
"message" => [
"token" => $deviceToken,
"notification" => [
"title" => "Title",
"body" => "Test Body"
]
// Puedes agregar "data" u otros campos si es necesario.
]
];
// Endpoint de la API HTTP v1 de FCM. Reemplaza {projectId} por el valor obtenido.
$url = "https://fcm.googleapis.com/v1/projects/{$projectId}/messages:send";
// Cabeceras de la petición, incluyendo el token de acceso OAuth obtenido.
$headers = [
"Authorization: Bearer " . $accessToken,
"Content-Type: application/json"
];
// Enviar la petición POST usando cURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message));
$result = curl_exec($ch);
if(curl_errno($ch)) {
return new JsonResponse([
'status' => 'error',
'message' => curl_error($ch)
]);
}
curl_close($ch);
return new JsonResponse([
'status' => 'success',
'result' => $result
]);
}
private function getAccessToken($serviceAccountFile)
{
// Lee las credenciales desde el archivo JSON.
$credentials = json_decode(file_get_contents($serviceAccountFile), true);
$privateKey = $credentials['private_key'];
$clientEmail = $credentials['client_email'];
$tokenUri = $credentials['token_uri']; // Normalmente "https://oauth2.googleapis.com/token"
// Construir el header del JWT.
$header = json_encode([
'alg' => 'RS256',
'typ' => 'JWT'
]);
// Construir el payload (claims).
$now = time();
$claims = json_encode([
'iss' => $clientEmail,
'scope' => 'https://www.googleapis.com/auth/firebase.messaging',
'aud' => $tokenUri,
'iat' => $now,
'exp' => $now + 3600 // El token es válido por 1 hora.
]);
// Función anónima para hacer Base64URL encoding.
$base64UrlEncode = function($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
};
$base64UrlHeader = $base64UrlEncode($header);
$base64UrlClaims = $base64UrlEncode($claims);
// Crear la cadena a firmar: header.claims.
$signatureInput = $base64UrlHeader . '.' . $base64UrlClaims;
// Firmar la cadena usando la clave privada con SHA256.
$signature = '';
openssl_sign($signatureInput, $signature, $privateKey, 'SHA256');
$base64UrlSignature = $base64UrlEncode($signature);
// Construir el JWT completo.
$jwt = $signatureInput . '.' . $base64UrlSignature;
// Preparar la petición POST para intercambiar el JWT por un token de acceso.
$postFields = http_build_query([
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $jwt
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $tokenUri);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if(curl_errno($ch)) {
die('Curl error: ' . curl_error($ch));
}
curl_close($ch);
$responseData = json_decode($response, true);
if(isset($responseData['access_token'])){
return $responseData['access_token'];
} else {
die('Error al obtener el token de acceso: ' . $response);
}
}
/**
* @Route("/get-bulletin", name="ws_get_bulletin", methods={"GET", "POST"})
*/
public function getBulletin(NotificationRepository $notificationRepository, NotificationReportRepository $notificationReportRepository, NotificationPushReportRepository $notificationPushReportRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$paths = $helperService->getPaths();
$token = $data->token;
$array = [];
$totalUnread = 0;
$notifications = $notificationRepository->findBy(["is_active" => 1, 'notification_type' => 'notification', 'Organization' => $token->organization_id], ["created_at" => "DESC"]);
foreach($notifications as $noti)
{
if($noti->getScheduledAt() <= date("Y-m-d H:i:s"))
{
//Buscamos usuarios a quienes se les enviara la notificación
$array_filters = [
"filter_age_from" => $noti->getFilterAgeFrom(),
"filter_age_to" => $noti->getFilterAgeTo(),
"filter_gender" => $noti->getFilterGender(),
"filter_user_id" => ($noti->getFilterUserId() != "" ? $noti->getFilterUserId()->getId() : '')
];
$users = $notificationPushReportRepository->getUsersNotifications($array_filters, $token->organization_id);
foreach($users as $user)
{
//$output->writeln([$user['id']]);
if($noti->getFilterAgeFrom() != '' || $noti->getFilterAgeTo() != '')
{
//calculamos edad en base a fecha de nacimiento
if($user['birthdate'] == '')
{
continue;
}
$age = $this->search_age($user['birthdate']);
if($noti->getFilterAgeFrom() != '' && intval($age) < intval($noti->getFilterAgeFrom()))
{
continue;
}
if($noti->getFilterAgeTo() != '' && $age > $noti->getFilterAgeTo())
{
continue;
}
}
if($token->id == $user['id'])
{
$imagePath = "";
if($noti->getImagePath() != '')
{
$imagePath = $paths['uploads_path']."/".$noti->getImagePath();
}
$wasRead = 0;
$checkRead = $notificationReportRepository->findOneBy(['user'=>$token->id, 'notification'=>$noti->getNotificationId()]);
if($checkRead)
{
$wasRead = 1;
} else {
$totalUnread++;
}
$array[] = [
'notification_id' => $noti->getNotificationId(),
'title' => $noti->getTitle(),
'short_content' => $noti->getShortContent(),
'large_content' => $noti->getTextContent(),
'image_path' => $imagePath,
'created_at' => $noti->getCreatedAt()->format("Y/m/d"),
'scheduled_at' => $noti->getScheduledAt(),
'is_scheduled' => $noti->getIsScheduled(),
'was_read' => $wasRead,
'created_by' => $noti->getCreatedBy()->getFirstName()." ".$noti->getCreatedBy()->getLastName()
];
}
}
}
}
/*$list = $notificationRepository->findBy(["is_active" => 1, 'Organization' => $token->organization_id], ["created_at" => "DESC"]);
foreach($list as $item)
{
$imagePath = "";
if($item->getImagePath() != '')
{
$imagePath = $paths['uploads_path']."/".$item->getImagePath();
}
$array[] = [
'notification_id' => $item->getNotificationId(),
'title' => $item->getTitle(),
'short_content' => $item->getShortContent(),
'large_content' => $item->getTextContent(),
'image_path' => $imagePath,
'created_at' => $item->getCreatedAt()->format("Y/m/d"),
'scheduled_at' => $item->getScheduledAt(),
'is_scheduled' => $item->getIsScheduled(),
'created_by' => $item->getCreatedBy()->getFirstName()." ".$item->getCreatedBy()->getLastName()
];
}*/
return new JsonResponse(array('status' => 'success', 'data' => $array, 'total_unread' => $totalUnread));
}
return new JsonResponse(array('status' => 'error', 'total_unread' => 0));
}
/**
* @Route("/get-events", name="ws_get_events", methods={"GET", "POST"})
*/
public function getEvents(EventListRepository $eventListRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$paths = $helperService->getPaths();
$token = $data->token;
$monthN=array(1=>"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
$array = [];
$list = $eventListRepository->findBy(["is_active" => 1, "is_publish" => 1, 'Organization' => $token->organization_id], ["created_at" => "ASC"]);
foreach($list as $item)
{
if($item->getScheduledAt() >= date("Y-m-d H:i:s"))
{
$explodeScheduled = explode("-",$item->getScheduledAt());
$month = str_replace("0","",$explodeScheduled[1]);
$monthNumber = $monthN[$month];
$bkg_img = "";
if($item->getBkgImage())
{
$bkg_img = $paths['uploads_path']."/".$item->getOrganization()->getOrganizationId()."/".$item->getBkgImage();
}
$array[] = [
'event_list_id' => $item->getEventListId(),
'title' => $item->getName(),
'description' => $item->getDescription(),
'bkg_image' => $bkg_img,
'created_at' => $item->getCreatedAt()->format("Y-m-d"),
'scheduled_at' => $item->getScheduledAt(),
'month_name' => substr($monthNumber,0,3),
'month_full' => $monthNumber,
'created_by' => $item->getCreatedBy()->getFirstName()." ".$item->getCreatedBy()->getLastName()
];
}
}
return new JsonResponse(array('status' => 'success', 'data' => $array));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/get-my-appointments", name="ws_get_my_appointments", methods={"GET", "POST"})
*/
public function getMyAppointments(AppointmentRepository $appointmentRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$token = $data->token;
$category = $data->category;
$array = [];
$item = $appointmentRepository->findOneBy(["AppointmentStatus" => 1, 'created_by' => $token->id, 'ConferenceCategory' => $category]);
if($item)
{
$to_time = strtotime($item->getScheduledAt());
$from_time = strtotime(date("Y-m-d H:i:s"));
$minutes_to_start = round(abs($to_time - $from_time) / 60,2). " minute";
$array = [
'appointment_id' => $item->getAppointmentId(),
'professional_id' => $item->getUser()->getId(),
'professional_name' => $item->getUser()->getFirstName()." ".$item->getUser()->getLastName(),
'scheduled_at' => $item->getScheduledAt(),
'minutes_to_start' => (int)$minutes_to_start,
'url' => "https://meet.jit.si/iglesiavirtual123435444".$item->getAppointmentId()
];
}
return new JsonResponse(array('status' => 'success', 'data' => $array));
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/change_password", name="ws_change_password", methods={"GET", "POST", "OPTIONS"})
*/
public function changePasswordAction(Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response {
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$user = $data->token;
$new = $data->new;
$em = $this->getDoctrine()->getManager();
$userObj = $entityManager->getRepository(\App\Entity\User::class)->findOneBy([
'id' => $user->id
]);
if($userObj) //&& $this->passwordEncoder->isPasswordValid($userObj, $current))
{
$new = $this->passwordEncoder->encodePassword($userObj, $new);
$userObj->setPassword($new);
$entityManager->persist($userObj);
$entityManager->flush();
if($userObj->getEmail())
{
$organizationName = $userObj->getOrganization()->getName();
$message = "<h1>Tu password ha cambiado</h1><p>Tu password ha sido cambiado correctamente. Si esta acción no fue realizada por tí, ponte en contacto con soporte ténico para reportar el incidente.</p>";
$mailTo = $userObj->getEmail();
$subject = "Cambio de Password";
$paths = $helperService->getPaths();
$logo = $paths['uploads_path'].$userObj->getOrganization()->getLogoPath();
if($helperService->sendEmail($mailTo, $subject, $message, false, $organizationName, $logo))
{
return new JsonResponse(array('status' => 'success', 'msg' => ''));
} else {
return new JsonResponse(array('status' => 'error', 'msg' => 'No se pudo enviar el email de recuperación. Contacte con soporte técnico.'));
}
} else {
return new JsonResponse(array('status' => 'error'));
}
} else {
return new JsonResponse(array('status' => 'invalid'));
}
}
return new JsonResponse(array('status' => 'error'));
}
/**
* @Route("/get-conference-status", name="/ws_get_conference_status")
*/
public function getConferenceStatusAction(AppointmentRepository $appointmentRepository, Request $request, EntityManagerInterface $entityManager): Response
{
$list = array();
$status = 0;
$rating = 0;
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$aid = $data->aid;
$uid = $data->uid;
$appointment = $appointmentRepository->findOneBy(['appointmentId' => $aid]);
if($appointment)
{
$userRating = 0;
$status = $appointment->getAppointmentStatus()->getAppointmentStatusId();
}
}
$url = "https://meet.jit.si";
return new JsonResponse(array('aid_status' => $status, 'rating' => 0, 'url' => $url));
}
/**
* @Route("/get-events-list", name="ws_get_events_list", methods={"GET", "POST"})
*/
public function getEventsList(EventListRepository $eventListRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$paths = $helperService->getPaths();
$organizationId = $request->get("oid");
$limit = $request->get("limit");
$monthN = array(1=>"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
$array = [];
$list = $eventListRepository->findBy(["is_active" => 1, "is_publish" => 1, 'Organization' => $organizationId], ["created_at" => "ASC"], $limit);
foreach($list as $item)
{
if($item->getScheduledAt() >= date("Y-m-d H:i:s"))
{
$scheduled = new \DateTime($item->getScheduledAt());
$final_scheduled = $this->spanish_date($scheduled->format('D M j, H:i'));
$explodeScheduled = explode("-",$item->getScheduledAt());
$month = str_replace("0","",$explodeScheduled[1]);
$monthNumber = $monthN[$month];
$bkg_img = "";
if($item->getBkgImage())
{
$bkg_img = $paths['uploads_path']."/".$item->getBkgImage();
}
$array[] = [
'event_list_id' => $item->getEventListId(),
'title' => $item->getName(),
'description' => $item->getDescription(),
'bkg_image' => $bkg_img,
'created_at' => $item->getCreatedAt()->format("Y-m-d"),
'scheduled_at' => $final_scheduled,
'month_name' => substr($monthNumber,0,3),
'month_full' => $monthNumber,
'created_by' => $item->getCreatedBy()->getFirstName()." ".$item->getCreatedBy()->getLastName()
];
}
}
return new JsonResponse(array('status' => 'success', 'data' => $array));
}
/**
* @Route("/get-blog-list", name="/ws_get_blog_list")
*/
public function getBlogListAction(BlogRepository $blogRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$list = [];
//$data = json_decode(file_get_contents("php://input"));
if(true)//$data)
{
$organizationId = $request->get("oid");
$limit = $request->get("limit");
$id = $request->get("bid", 0);
$cid = $request->get("cid", 0);
$next = ["title"=>"","bid"=>0];
$previous = ["title"=>"","bid"=>0];
if($id <> 0)
{
$nextObjects = $blogRepository->findBlogCompanion($id, 'next', $organizationId);
$previousObjects = $blogRepository->findBlogCompanion($id, 'previous', $organizationId);
if($nextObjects)
{
$next = ["title" => $nextObjects['name'], "bid" => $nextObjects['blog_id']];
}
if($previousObjects)
{
$previous = ["title" => $previousObjects['name'], "bid" => $previousObjects['blog_id']];
}
$blogs = $blogRepository->findBy(['is_active' => 1, 'is_publish' => 1, 'Organization' => $organizationId, 'blogId' => $id]);
} else {
if($cid > 0)
{
$blogs = $blogRepository->findBy([
'is_active' => 1,
'is_publish' => 1,
'BlogCategory' => $cid,
'Organization' => $organizationId],
['created_at' => 'DESC'], $limit);
} else {
$blogs = $blogRepository->findBy([
'is_active' => 1,
'is_publish' => 1,
'Organization' => $organizationId],
['created_at' => 'DESC'], $limit);
}
}
if($blogs)
{
$paths = $helperService->getPaths();
foreach($blogs as $blog)
{
$creation = new \DateTime($blog->getCreatedAt()->format("Y-m-d H:i:s"));
$final_creation = $this->spanish_date($creation->format('D M j, H:i'));
$bkg = $paths['uploads_path'].$blog->getOrganization()->getOrganizationId()."/".$blog->getBkgImage();
$list[] = [
'blog_id' => $blog->getBlogId(),
'name' => $blog->getName(),
'short_content' => $blog->getShortContent(),
'category_id' => $blog->getBlogCategory()->getBlogCategoryId(),
'large_content' => $blog->getLargeContent(),
'category' => $blog->getBlogCategory()->getName(),
'bkg_image' => $bkg,
'creator_name' => $blog->getCreatedBy()->getFirstName()." ".$blog->getCreatedBy()->getLastName(),
'created_at' => $final_creation
];
}
}
}
return new JsonResponse(array('status' => "success", 'data' => $list, 'next' => $next, 'previous' => $previous));
}
/**
* @Route("/get-blog-categories", name="/ws_get_blog_categories")
*/
public function getBlogCategoriesAction(BlogCategoryRepository $blogCategoryRepository,BlogRepository $blogRepository, Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$list = [];
$organizationId = $request->get("oid");
$total = 0;
if($organizationId)
{
$blogs = $blogCategoryRepository->findBy(['is_active' => 1, 'Organization' => $organizationId], ['name' => 'ASC']);
if($blogs)
{
foreach($blogs as $blog)
{
$results = $blogRepository->findBy(['BlogCategory' => $blog->getBlogCategoryId(), 'is_active' => 1]);
if($results)
{
$count = count($results);
$list[] = [
'blog_category_id' => $blog->getBlogCategoryId(),
'name' => $blog->getName(),
'description' => $blog->getDescription(),
'count' => $count
];
$total = $total+$count;
}
}
}
}
return new JsonResponse(array('status' => "success", 'data' => $list, 'total_blogs' => $total));
}
/**
* @Route("/pass-recovery", name="ws_pass_recovery")
*/
public function recoverPassword(Request $request, HelperService $helperService, UserRepository $userRepository, EntityManagerInterface $entityManager): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$email = $data->email;
$organizacionId = $data->organization_id;
$userCheck = $userRepository->findOneBy(['email' => $email, 'status' => 'ACTIVO', 'Organization' => $organizacionId]);
if($userCheck)
{
$plainpwd = substr(md5(microtime()),rand(0,26),8)."*";
$encoded = $this->passwordEncoder->encodePassword($userCheck, $plainpwd);
$userCheck->setPassword($encoded);
$entityManager->persist($userCheck);
$entityManager->flush();
$organizationName = $userCheck->getOrganization()->getName();
$message = "<p>Ha solicitado recuperar la contraseña para su cuenta en la Plataforma de $organizationName. Puede utilizar el siguiente password para iniciar sesión.</p>";
$message .= "<p><b>Contraseña temporal:</b> $plainpwd</p>";
$message .= "<p>Una vez dentro de su cuenta, no olvide cambiar su contraseña.</p>";
$mailTo = $data->email;
$subject = "Recuperación de contraseña";
$paths = $helperService->getPaths();
$logo = $paths['uploads_path'].$userCheck->getOrganization()->getLogoPath();
if($helperService->sendEmail($mailTo, $subject, $message, false, $organizationName, $logo))
{
return new JsonResponse(array('status' => 'success', 'msg' => ''));
} else {
return new JsonResponse(array('status' => 'error', 'msg' => 'No se pudo enviar el email de recuperación. Contacte con soporte técnico.'));
}
} else {
return new JsonResponse(array('status' => 'error', 'msg' => 'El email no se encuentra registrado.'));
}
}
return new JsonResponse(array('status' => 'invalid', 'msg' => ''));
}
/**
* @Route("/voice_trainer_list", name="/ws_voice-trainer-list", methods={"GET", "POST"})
*/
public function getVoiceTrainerList(Request $request, EntityManagerInterface $entityManager, HelperService $helperService): Response
{
$list = [];
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$type = $data->type;
$objs = $entityManager->getRepository(VoiceExercise::class)->findBy(['is_active' => 1,'exercise_type' => $type]);
if($objs)
{
foreach($objs as $obj)
{
$paths = $helperService->getPaths();
$voicePath = $paths['uploads_path']."voice/";
$list[] = [
'voice_exercise_id' => $obj->getVoiceExerciseId(),
'name' => $obj->getName(),
'image' => $voicePath.$obj->getImagePath(),
'description' => $obj->getDescription(),
'file_path' => $voicePath.$obj->getFilePath(),
'task_id' => '',
'task_detail_id' => ''
];
}
}
}
return new JsonResponse(array('status' => "success", 'data' => $list));
}
/**
* @Route("/voice_trainer_save_record", name="ws_voice_trainer_save_record", methods={"GET", "POST"})
*/
public function voiceTrainerSaveRecord(UserRepository $userRepository, Request $request, EntityManagerInterface $entityManager, UserRoleRepository $userRoleRepository,OrganizationRepository $organizationRepository, HelperService $helperService): Response
{
$data = json_decode(file_get_contents("php://input"));
if($data)
{
$record = $data->record;
$token = $data->token;
$exerciseId = $data->exercise->voice_exercise_id;
$userId = $token->id;
$paths = $helperService->getPaths();
$voicePath = $paths['uploads_path']."voice/";
$dir_path = "uploads/voice/$userId/";
if(!is_dir($dir_path))
{
mkdir($dir_path, 0777, true);
}
$hashName = date("YmdHis").rand(1,10);
$fileName = $hashName."_voice_only.acc";
$accFile = $dir_path.$fileName;
file_put_contents($accFile, base64_decode($record));
$exerciseObj = $entityManager->getRepository(VoiceExercise::class)->findOneBy(['voiceExerciseId' => $exerciseId]);
$uri = $paths['uri'];
// Rutas de los archivos de entrada
$mp3File = $uri.'uploads/voice/'.$exerciseObj->getFilePath();
// Ruta del archivo de salida combinado
$outputFile = $uri.'uploads/voice/'.$userId."/".$hashName."_merged.mp3";
// Convertir el archivo ACC a MP3
$wavFile = $uri."uploads/voice/".$userId."/".$hashName.'_temp.wav';
// Ruta del archivo de salida combinado
$outputFile = $uri."uploads/voice/".$userId."/".$hashName."_combinado.mp3";
$fullAccFile = $uri.$accFile;
// Convertir el archivo ACC a MP3
$convertedAccFile = $uri."uploads/voice/".$userId."/".$hashName."_convertido.mp3";
$shell1 = "ffmpeg -i $fullAccFile $convertedAccFile";
exec($shell1);
// Combinar los archivos MP3
$shell2 = "ffmpeg -i 'concat:$mp3File|$convertedAccFile' -c copy $outputFile";
exec($shell2);
// Eliminar el archivo convertido ACC a MP3
//unlink($convertedAccFile);
$extra = [
'shell1' => $shell1,
'shell2' => $shell2
];
return new JsonResponse(array('status' => 'success','data' => $extra));
}
return new JsonResponse(array('status' => 'error'));
}
function search_age($birthdate)
{
$day = date("d");
$month = date("m");
$year = date("Y");
$daynaz = date("d",strtotime($birthdate));
$monthnaz = date("m",strtotime($birthdate));
$yearnaz = date("Y",strtotime($birthdate));
//si el mes es el mismo pero el día inferior aun no ha cumplido años, le quitaremos un año al actual
if (($monthnaz == $month) && ($daynaz > $day)) {
$year=($year-1); }
//si el mes es superior al actual tampoco habrá cumplido años, por eso le quitamos un año al actual
if ($monthnaz > $month) {
$year=($year-1);}
//ya no habría mas condiciones, ahora simplemente restamos los años y mostramos el resultado como su edad
$age=($year-$yearnaz);
return $age;
}
public function spanish_date($date)
{
$arr = explode(" ", $date);
$day = $arr[0];
$month = $arr[1];
$num = $arr[2];
$hour = $arr[3];
$day_name = $day;
$mon_name = $month;
switch($day)
{
case "Mon":
$day_name = "Lun";
break;
case "Tue":
$day_name = "Mar";
break;
case "Wed":
$day_name = "Mie";
break;
case "Thu":
$day_name = "Jue";
break;
case "Fri":
$day_name = "Vie";
break;
case "Sat":
$day_name = "Sab";
break;
case "Sun":
$day_name = "Dom";
break;
}
switch($mon_name)
{
case "Jan":
$mon_name = "Ene";
break;
case "Feb":
$mon_name = "Feb";
break;
case "Mar":
$mon_name = "Mar";
break;
case "Apr":
$mon_name = "Abr";
break;
case "May":
$mon_name = "May";
break;
case "Jun":
$mon_name = "Jun";
break;
case "Jul":
$mon_name = "Jul";
break;
case "Aug":
$mon_name = "Ago";
break;
case "Sep":
$mon_name = "Sep";
break;
case "Oct":
$mon_name = "Oct";
break;
case "Nov":
$mon_name = "Nov";
break;
case "Dec":
$mon_name = "Dic";
break;
}
return $day_name." ".$mon_name." ".$num." ".$hour;
}
}