557 lines
31 KiB
PHP
557 lines
31 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use Illuminate\Http\Request;
|
||
use App\Http\Requests\LambdaRequest;
|
||
use App\Http\Requests\Creation;
|
||
use App\Models\Library;
|
||
use App\Models\Session;
|
||
use App\Models\Sessionagenda;
|
||
use App\Models\Faculty;
|
||
use App\Mail\SessionMessage;
|
||
use App\Services\SessionCommunicationService;
|
||
use Illuminate\Support\Facades\Mail;
|
||
use DB;
|
||
use PDF;
|
||
use Storage;
|
||
use Response;
|
||
use Log;
|
||
|
||
class MicrositeController extends LocalController
|
||
{
|
||
public function contentlibrary($code, Request $request)
|
||
{
|
||
$library = Library::where('code', $code)->first();
|
||
$library->library_values = json_decode($library->library_values);
|
||
$content_id = $request->input('id', false);
|
||
if (!$content_id) {
|
||
$content_id = $library->library_values[0]->id;
|
||
}
|
||
$library = (object)$library->toArray();
|
||
$library->session_code = '';
|
||
$code = '';
|
||
if ($library->session_id > 0) {
|
||
$session = Session::find($library->session_id);
|
||
$session->dates = json_decode($session->dates);
|
||
$library->session_code = $session->code;
|
||
$code = $session->code;
|
||
}
|
||
$content = LambdaRequest::getrequest('mag', 'magazine/details', ['id' => $content_id], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
$islogged = false;
|
||
if ($request->session()->has('content_' . $code . '_user_id')) {
|
||
$islogged = true;
|
||
$library->contact_id = $request->session()->get('content_' . $code . '_user_id');
|
||
}
|
||
//echo '<pre>'; print_r($content); exit;
|
||
return view('road.contentlibrary', ['library' => $library, 'content' => $content->data, 'islogged' => $islogged, 'session' => $session]);
|
||
}
|
||
|
||
public function contentlibrarylogin(Request $request)
|
||
{
|
||
$post = $request->except('_token');
|
||
$code = $post['session_code'];
|
||
$phone = $post['phone'];
|
||
$response = LambdaRequest::getrequest('contact', 'contact/get_all', ['source' => 'dynamodb', 'search' => json_encode(['session_code' => $code, 'phone' => $phone]), 'fields' => json_encode(['session_code', 'present'])], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
if (sizeof($response->data->items) > 0) {
|
||
$request->session()->put('content_' . $code . '_user_id', $response->data->items[0]->id);
|
||
return response()->json(['status' => 'success', 'id' => $response->data->items[0]->id]);
|
||
} else {
|
||
return response()->json(['status' => 'failed']);
|
||
}
|
||
//echo '<pre>'; echo json_encode(['session_code' => $code, 'phone' => $phone]); print_r($response); print_r($post); exit;
|
||
}
|
||
|
||
public function analytics_view(Request $request)
|
||
{
|
||
$post = $request->except('_token');
|
||
$post['ip'] = $request->ip();
|
||
$content = LambdaRequest::postrequest('mag', 'mag_media_views/create_multiple', $post, env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
return response()->json($content);
|
||
}
|
||
|
||
public function microsite($code, Request $request)
|
||
{
|
||
list($type, $code) = explode('-', $code);
|
||
$session = (object)Session::where('code', $code)->first()->toArray();
|
||
$session->dates = json_decode($session->dates);
|
||
$session->faculty = explode('|', $session->faculty);
|
||
$session->faculty = array_filter($session->faculty, function ($value) {
|
||
return !is_null($value) && $value !== '';
|
||
});
|
||
$faculties = Faculty::whereIn('id', $session->faculty)->orderby('sort_order')->get();
|
||
$agendas = Sessionagenda::where('session_id', $session->id)->get();
|
||
//echo '<pre>'; print_r(['session' => $session, 'faculties' => $faculties]); exit;
|
||
return view($session->type . '.microsite', ['session' => $session, 'faculties' => $faculties, 'agendas' => $agendas]);
|
||
}
|
||
|
||
//
|
||
public function brochure($code, Request $request)
|
||
{
|
||
$fresh = $request->input('fresh', 0);
|
||
if (!$fresh && Storage::disk('local')->has('public/brochure/' . $code . '.pdf')) {
|
||
$headers = array('Content-Type: application/pdf',);
|
||
//echo storage_path().'/storage/brochure/'.$code.'.pdf'; exit;
|
||
return Response::download(storage_path() . '/app/public/brochure/' . $code . '.pdf', 'brochure.pdf', $headers);
|
||
} else {
|
||
$session = (object)Session::where('code', $code)->first()->toArray();
|
||
$session->dates = json_decode($session->dates);
|
||
$session->faculty = explode('|', $session->faculty);
|
||
$session->faculty = array_filter($session->faculty, function ($value) {
|
||
return !is_null($value) && $value !== '';
|
||
});
|
||
$faculties = Faculty::whereIn('id', $session->faculty)->orderby('sort_order')->get();
|
||
$agendas = Sessionagenda::where('session_id', $session->id)->get();
|
||
//echo '<pre>'; print_r(['session' => $session, 'faculties' => $faculties]); exit;
|
||
//return view($session->type.'.brochure', ['session' => $session, 'faculties' => $faculties, 'agendas' => $agendas]);
|
||
|
||
@ini_set('memory_limit', '512M');
|
||
$pdf = PDF::loadView($session->type . '.brochure', ['session' => $session, 'faculties' => $faculties, 'agendas' => $agendas])->setOptions(['defaultFont' => 'sans-serif', 'isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true]);
|
||
if ($session->type == 'casper' || $session->type == 'casper_clinic') {
|
||
$customPaper = array(0, 0, 500, 750);
|
||
$pdf->setPaper($customPaper);
|
||
}
|
||
if ($session->type == 'ecampus') {
|
||
$customPaper = array(0, 0, 650, 950);
|
||
$pdf->setPaper($customPaper);
|
||
}
|
||
Storage::put('public/brochure/' . $code . '.pdf', $pdf->output());
|
||
//return $pdf->download('brochure.pdf');
|
||
return $pdf->stream();
|
||
}
|
||
}
|
||
|
||
public function register($code, Request $request)
|
||
{
|
||
$sessionModel = Session::where('code', $code)->first();
|
||
$session = (object) $sessionModel->toArray();
|
||
$linked_user = $request->input('linked_user', false);
|
||
$session->dates = json_decode($session->dates);
|
||
$request->session()->put('session_type', $session->type);
|
||
$request->session()->put('linked_user', $linked_user);
|
||
$comm = app(SessionCommunicationService::class);
|
||
|
||
return view($session->type . '.register', [
|
||
'session' => $session,
|
||
'communication_mode' => $comm->resolveMode($sessionModel),
|
||
]);
|
||
}
|
||
|
||
public function postregister($code, Request $request)
|
||
{
|
||
$post = $request->except('_token');
|
||
$post['type_of_setup'] = isset($post['type_of_setup']) ? implode(',', $post['type_of_setup']) : [];
|
||
$linked_user = $request->session()->get('linked_user');
|
||
|
||
$post['session_code'] = $code;
|
||
$request->session()->put('session_code', $code);
|
||
$request->session()->put('is_linked_user', $linked_user ? 'yes': 'no');
|
||
|
||
if($linked_user) {
|
||
$post['user_id'] = $linked_user;
|
||
$post['is_verified'] = true;
|
||
$response = LambdaRequest::postrequest('contact', 'contact/createforcrest', $post, env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
$session_type = $request->session()->get('session_type');
|
||
LambdaRequest::getrequest('detailing', 'group/addusertogroup', ['group_id' => '1725877244-41845d6e-9948-4bdf-a254-'.$session_type, 'user_id' => $linked_user], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
} else {
|
||
$post['position'] = 'india';
|
||
$response = LambdaRequest::postrequest('contact', 'contact/create', $post, env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
}
|
||
|
||
Log::debug(print_r($response, true));
|
||
if ($response->status == 'success') {
|
||
Session::where('code', $code)->increment('reg_count');
|
||
if($linked_user) {
|
||
Session::where('code', $code)->increment('reg_confirmed');
|
||
}
|
||
// $session = (object)Session::where('code', $code)->first()->toArray();
|
||
// $client = new \GuzzleHttp\Client();
|
||
// $text = 'Greetings ' . $post['name']."\n";
|
||
// $text .= 'You have Successfully registered for Crest session "'.$session->number.' ('.$session->type.') "'."\n";
|
||
// $text .= 'Please find the details below'."\n";
|
||
// $text .= 'Venue: ' . $session->venue . "\n";
|
||
// $text .= 'Address: ' . $session->address . "\n";
|
||
// $text .= 'Timings:' . "\n";
|
||
// $dates = json_decode($session->dates);
|
||
// foreach($dates->date as $i => $date){
|
||
// $text .= date("d M, Y", strtotime($date) ) . ' at ' . date("h:iA", strtotime($dates->start[$i]) ) .' - ' . date("h:iA", strtotime($dates->end[$i]) ) . "\n";
|
||
// }
|
||
// $text .= "\n" . 'You can use this chat as your self assistance for getting details, download your certificate etc.';
|
||
// $res = $client->get('https://panel.rapiwha.com/send_message.php', ['query' => ['apikey' => 'Z4NXQUTBGV3P7D7W8OHX', 'number' => '91'.$post['phone'], 'text' => $text], 'timeout' => 10]);
|
||
// $res = $res->getBody();
|
||
$contactId = $response->data->item->id ?? null;
|
||
$request->session()->put('session_user_id', $contactId);
|
||
if (!empty($post['email'])) {
|
||
$request->session()->put('session_user_email', $post['email']);
|
||
}
|
||
if (!empty($post['name'])) {
|
||
$request->session()->put('session_user_name', $post['name']);
|
||
}
|
||
$request->session()->save();
|
||
|
||
$session = Session::where('code', $code)->first();
|
||
$comm = app(SessionCommunicationService::class);
|
||
if ($session && !$linked_user && $comm->shouldSendEmail($comm->resolveMode($session))) {
|
||
$this->sendRegistrationVerificationEmail($session, $response->data->item->id, $post['email'], $post['name'] ?? '');
|
||
}
|
||
|
||
if($linked_user) {
|
||
return redirect('/registersuccess')->withSuccess('Successfully registered for Session!!');
|
||
} else {
|
||
return redirect('/registersuccess')->withSuccess('Successfully registered!!');
|
||
}
|
||
|
||
|
||
} else {
|
||
return redirect('/register/' . $code)->withError('Some error occured, please try again later');
|
||
}
|
||
}
|
||
|
||
public function registersuccess(Request $request)
|
||
{
|
||
$code = $request->session()->get('session_code');
|
||
$type = $request->session()->get('session_type');
|
||
$linked_user = $request->session()->get('linked_user');
|
||
$user_id = $request->session()->get('session_user_id');
|
||
$user_email = $request->session()->get('session_user_email');
|
||
|
||
$session = $code ? Session::where('code', $code)->first() : null;
|
||
$comm = app(SessionCommunicationService::class);
|
||
$communication_mode = $comm->resolveMode($session);
|
||
|
||
return view('road.success', [
|
||
'code' => $code,
|
||
'type' => $type,
|
||
'user_id' => $user_id,
|
||
'linked_user' => $linked_user,
|
||
'communication_mode' => $communication_mode,
|
||
'user_email' => $user_email,
|
||
'email_verified' => $request->session()->get('email_verified', false),
|
||
'microsite_url' => ($type && $code) ? url('/microsite/' . $type . '-' . $code) : null,
|
||
]);
|
||
}
|
||
|
||
public function verifyRegistration(Request $request, $code, $user_id)
|
||
{
|
||
$session = Session::where('code', $code)->first();
|
||
if (!$session) {
|
||
return redirect('/')->withError('Invalid verification link.');
|
||
}
|
||
|
||
LambdaRequest::postrequest(
|
||
'contact',
|
||
'contact/update',
|
||
['id' => $user_id, 'position' => 'india', 'is_verified' => true],
|
||
env('LAMBDA_ACCESS_TOKEN', 'default_value')
|
||
);
|
||
|
||
Session::where('code', $code)->increment('reg_confirmed');
|
||
|
||
$request->session()->put('session_code', $code);
|
||
$request->session()->put('session_type', $session->type);
|
||
$request->session()->put('email_verified', true);
|
||
$request->session()->put('is_linked_user', 'no');
|
||
|
||
return redirect('/registersuccess')
|
||
->withSuccess('Your email has been confirmed successfully.');
|
||
}
|
||
|
||
public function resendVerificationEmail(Request $request)
|
||
{
|
||
$code = $request->input('code') ?: $request->session()->get('session_code');
|
||
$user_id = $request->input('user_id') ?: $request->session()->get('session_user_id');
|
||
$email = $request->input('email') ?: $request->session()->get('session_user_email');
|
||
$name = $request->input('name') ?: $request->session()->get('session_user_name', '');
|
||
|
||
if ($code) {
|
||
$request->session()->put('session_code', $code);
|
||
}
|
||
if ($user_id) {
|
||
$request->session()->put('session_user_id', $user_id);
|
||
}
|
||
if ($email) {
|
||
$request->session()->put('session_user_email', $email);
|
||
}
|
||
|
||
$session = $code ? Session::where('code', $code)->first() : null;
|
||
|
||
if ($user_id && !$email) {
|
||
$contactResponse = LambdaRequest::getrequest(
|
||
'contact',
|
||
'contact/get_one',
|
||
['id' => $user_id],
|
||
env('LAMBDA_ACCESS_TOKEN', 'default_value')
|
||
);
|
||
if (!empty($contactResponse->data->item->email)) {
|
||
$email = $contactResponse->data->item->email;
|
||
$request->session()->put('session_user_email', $email);
|
||
}
|
||
if ($name === '' && !empty($contactResponse->data->item->name)) {
|
||
$name = $contactResponse->data->item->name;
|
||
}
|
||
}
|
||
|
||
if (!$session || !$user_id || !$email) {
|
||
Log::warning('Resend verification missing data', [
|
||
'code' => $code,
|
||
'user_id' => $user_id,
|
||
'email' => $email,
|
||
]);
|
||
return redirect('/registersuccess')->withError('Unable to resend verification email. Please register again.');
|
||
}
|
||
|
||
$sent = $this->sendRegistrationVerificationEmail($session, (string) $user_id, $email, $name);
|
||
|
||
if (!$sent) {
|
||
return redirect('/registersuccess')->withError('Could not send verification email. Please check the email address and try again.');
|
||
}
|
||
|
||
return redirect('/registersuccess')->withSuccess('Verification email sent again. Please check your inbox.');
|
||
}
|
||
|
||
protected function sendRegistrationVerificationEmail(Session $session, string $userId, string $email, string $name): bool
|
||
{
|
||
$email = trim($email);
|
||
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||
return false;
|
||
}
|
||
|
||
$verifyUrl = url('/verify-registration/' . $session->code . '/' . $userId);
|
||
$greeting = $name !== '' ? 'Hello ' . $name . ',' : 'Hello,';
|
||
|
||
$bodyHtml = '<p>' . e($greeting) . '</p>'
|
||
. '<p>Thank you for registering for <strong>' . e($session->number) . '</strong>.</p>'
|
||
. '<p>Please confirm your email address by clicking the button below:</p>'
|
||
. '<p style="text-align:center;margin:24px 0;">'
|
||
. '<a href="' . e($verifyUrl) . '" style="background-color:#1a3a5c;color:#ffffff;padding:12px 24px;text-decoration:none;border-radius:4px;display:inline-block;">Confirm your email</a>'
|
||
. '</p>'
|
||
. '<p style="font-size:13px;color:#666;">Or copy this link into your browser:<br>' . e($verifyUrl) . '</p>'
|
||
. '<p>If you did not register for this session, you can ignore this email.</p>'
|
||
. '<p>Regards,<br>CREST Team</p>';
|
||
|
||
$subject = 'Crest – Please confirm your email';
|
||
|
||
try {
|
||
Mail::to($email)->send(new SessionMessage($subject, $bodyHtml));
|
||
return true;
|
||
} catch (\Throwable $e) {
|
||
Log::error('Registration verification email failed: ' . $e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public function attendance($code, Request $request)
|
||
{
|
||
$session = (object)Session::where('code', $code)->first()->toArray();
|
||
$session->dates = json_decode($session->dates);
|
||
$response = LambdaRequest::getrequest('contact', 'contact/get_all', ['source' => 'dynamodb', 'search' => json_encode(['session_code' => $code]), 'fields' => json_encode(['session_code', 'present'])], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
|
||
// echo env('LAMBDA_ACCESS_TOKEN', 'default_value');
|
||
//echo '<pre>'; print_r(['source' => 'dynamodb', 'search' => json_encode(['session_code' => $code]), 'fields' => json_encode(['session_code', 'present'])]); print_r($response); print_r($session); exit;
|
||
return view($session->type . '.attendance', ['session' => $session, 'doctors' => $response->data->items]);
|
||
}
|
||
|
||
public function attendancemark(Request $request)
|
||
{
|
||
$post = $request->input();
|
||
$response = LambdaRequest::postrequest('contact', 'contact/update', ['id' => $post['doctor'], 'present' => $post['present'], 'position' => 'india'], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
|
||
|
||
echo '<pre>';
|
||
print_r($response);
|
||
exit;
|
||
}
|
||
|
||
public function joinmeeting($code, Request $request)
|
||
{
|
||
$session = (object)Session::where('code', $code)->first()->toArray();
|
||
return redirect($session->join_link);
|
||
}
|
||
public function feedbackform($code, Request $request)
|
||
{
|
||
list($code, $recipient) = explode('_', $code);
|
||
$session = (object)Session::where('code', $code)->first()->toArray();
|
||
if (empty($session->feedback_link)) {
|
||
$forsms = ['road' => '1671763320-62ba6179-fb51-4350-bed3-bbc4e15f4391', 'casper' => '1752837484-717ff050-cf05-4e93-86b0-d9e76bbf7e3f', 'casper_clinic' => '1671763322-62ba6179-fb51-4350-bed3-bbc4e15f4393', 'spirometry_simplified' => '1671763323-62ba6179-fb51-4350-bed3-bbc4e15f4394', 'APFT' => '1671763320-62ba6179-fb51-4350-bed3-bbc4e15f4391', 'casper_clinic_new' => '1723004438-58ea6609-6672-436a-97ad-681e5463d27d', 'casper_plus' => '1723004438-58ea6609-6672-436a-97ad-681e5463d27d', 'ecampus' => '1724666803-7c16a3f1-f294-4a4d-b068-0b829ecd8d37'];
|
||
$logos = ['road' => '/images/road-logo.jpg', 'casper' => '/casper/images/logo-left.png', 'casper_clinic' => '/casper_clinic/images/logo.png', 'spirometry_simplified' => '/spirometry_simplified/images/logo.png', 'APFT' => '/APFT/images/logo-left.png', 'casper_clinic_new' => '/casper_clinic_new/images/logo.png', 'casper_plus' => '/casper_plus/images/logo.png', 'ecampus' => '/ecampus/images/main-logo.png'];
|
||
$titles = ['road' => 'Refresher course on Obstructive Airways Diseases (ROAD)', 'casper' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER)', 'casper_clinic' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Clinics)', 'spirometry_simplified' => 'SPIROMETRY SIMPLIFIED', 'casper_clinic_new' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Clinics)', 'casper_plus' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Plus)', 'ecampus' => 'Online COPD & Asthma Module for Post Graduate Students'];
|
||
|
||
$session->dates = json_decode($session->dates);
|
||
$forinfo = LambdaRequest::postrequest('form', 'survey/getrawform', ['partition' => 'rapport-crestroad', 'form_id' => $forsms[$session->type]], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
||
|
||
// echo '<pre>'; print_r($forinfo); exit;
|
||
|
||
$forinfo = $forinfo->data;
|
||
$request->session()->put('forinfo', $forinfo->form);
|
||
// echo '<pre>'; print_r($session); print_r($forinfo); exit;
|
||
$data = [
|
||
'session' => $session, 'questions' => $forinfo->questions, 'form' => $forinfo->form, 'form_id' => $forinfo->form->id,
|
||
'logo' => $logos[$session->type], 'title' => $titles[$session->type], 'recipient' => $recipient
|
||
];
|
||
|
||
|
||
if (\View::exists($session->type.'.feedbackform-'.$forinfo->form->id)) {
|
||
return view($session->type.'.feedbackform-'.$forinfo->form->id)->with($data);
|
||
} else if (\View::exists($session->type.'.feedbackform')) {
|
||
return view($session->type.'.feedbackform')->with($data);
|
||
} else {
|
||
return view('road.feedbackform')->with($data);
|
||
}
|
||
|
||
//return view('road.feedbackform')->with($data);
|
||
} else {
|
||
return redirect($session->feedback_link);
|
||
}
|
||
}
|
||
|
||
public function feedbackformassessment($code, Request $request)
|
||
{
|
||
// list($code, $recipient) = explode('_', $code);
|
||
$session = (object)Session::where('code', $code)->first()->toArray();
|
||
if (empty($session->feedback_link)) {
|
||
$forsms = [
|
||
'road' => '1671763320-62ba6179-fb51-4350-bed3-bbc4e15f4391',
|
||
// 'casper' => '1671763321-62ba6179-fb51-4350-bed3-bbc4e15f4392',
|
||
'casper' => '1752837484-717ff050-cf05-4e93-86b0-d9e76bbf7e3f',
|
||
'casper_clinic' => '1671763322-62ba6179-fb51-4350-bed3-bbc4e15f4393',
|
||
'spirometry_simplified' => '1671763323-62ba6179-fb51-4350-bed3-bbc4e15f4394',
|
||
'APFT' => '1671763320-62ba6179-fb51-4350-bed3-bbc4e15f4391',
|
||
'casper_clinic_new' => '1723004438-58ea6609-6672-436a-97ad-681e5463d27d',
|
||
'casper_plus' => '1723004438-58ea6609-6672-436a-97ad-681e5463d27d',
|
||
'ecampus' => '1724666803-7c16a3f1-f294-4a4d-b068-0b829ecd8d37'
|
||
];
|
||
$logos = ['road' => '/images/road-logo.jpg', 'casper' => '/casper/images/logo-left.png', 'casper_clinic' => '/casper_clinic/images/logo.png', 'spirometry_simplified' => '/spirometry_simplified/images/logo.png', 'APFT' => '/APFT/images/logo-left.png', 'casper_clinic_new' => '/casper_clinic_new/images/logo.png', 'casper_plus' => '/casper_plus/images/logo.png', 'ecampus' => '/ecampus/images/main-logo.png'];
|
||
$titles = ['road' => 'Refresher course on Obstructive Airways Diseases (ROAD)', 'casper' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER)', 'casper_clinic' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Clinics)', 'spirometry_simplified' => 'SPIROMETRY SIMPLIFIED', 'casper_clinic_new' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Clinics)', 'casper_plus' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Plus)', 'ecampus' => 'Online COPD & Asthma Module for Post Graduate Students'];
|
||
|
||
$session->dates = json_decode($session->dates);
|
||
$forinfo = LambdaRequest::postrequest('form', 'survey/getrawform', ['partition' => 'rapport-crestroad', 'form_id' => $forsms[$session->type]], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
||
|
||
//echo '<pre>'; print_r($forinfo); exit;
|
||
|
||
$forinfo = $forinfo->data;
|
||
$request->session()->put('forinfo', $forinfo->form);
|
||
// echo '<pre>'; print_r($session); print_r($forinfo); exit;
|
||
$data = [
|
||
'session' => $session, 'questions' => $forinfo->questions, 'form' => $forinfo->form, 'form_id' => $forinfo->form->id,
|
||
'logo' => $logos[$session->type], 'title' => $titles[$session->type], 'recipient' => '$recipient'
|
||
];
|
||
|
||
if (\View::exists($session->type.'.feedbackform')) {
|
||
return view($session->type.'.feedbackform')->with($data);
|
||
} else {
|
||
return view('road.feedbackform')->with($data);
|
||
}
|
||
|
||
//return view('road.feedbackform')->with($data);
|
||
} else {
|
||
return redirect($session->feedback_link);
|
||
}
|
||
}
|
||
|
||
public function postfeedbackform($code, Request $request)
|
||
{
|
||
$post = $request->except('_token');
|
||
$forinfo = $request->session()->get('forinfo');
|
||
$response = LambdaRequest::postrequest('contact', 'contact/update', ['id' => $post['recipient'], 'feedback' => 'yes', 'position' => 'india'], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
//echo '<pre>'; print_r($post); print_r($response); exit;
|
||
$finfo = LambdaRequest::postrequest('form', 'survey/submitform', ['formdata' => $post, 'entity_id' => $forinfo->id, 'partition' => 'rapport-crestroad', 'user_id' => '1658768001-5e2d6e6b-16c7-40b2-93c7-68bf55772ff3'], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
// dd($finfo);
|
||
//echo '<pre>'; print_r($forinfo); print_r(json_encode($post)); print_r($finfo); exit;
|
||
$session_code = $finfo->data->submission->formdata->session_code;
|
||
$recipient = $finfo->data->submission->formdata->recipient;
|
||
$logos = ['road' => '/images/road-logo.jpg', 'casper' => '/casper/images/logo-left.png', 'casper_clinic' => '/casper_clinic/images/logo.png', 'spirometry_simplified' => '/spirometry_simplified/images/logo.png', 'APFT' => '/APFT/images/logo-left.png', 'casper_clinic_new' => '/casper_clinic_new/images/logo.png', 'casper_plus' => '/casper_plus/images/logo.png', 'ecampus' => '/ecampus/images/logo.png'];
|
||
// echo '<pre>'; print_r($session_code); print_r($recipient); exit;
|
||
|
||
$session_type = DB::table('sessions')->where('code', $session_code)->pluck('type');
|
||
// return $session_type[0];
|
||
$logo = $logos[$session_type[0]];
|
||
|
||
return view('road.feedbackformsuccess', compact('session_code', 'recipient', 'session_type', 'logo'));
|
||
|
||
//echo '<pre>'; print_r($finfo); print_r($post); print_r($forinfo); exit;
|
||
}
|
||
|
||
public function pre_impact_assessment($code, Request $request)
|
||
{
|
||
$parts = explode('_', $code, 2);
|
||
|
||
$code = $parts[0];
|
||
$recipient = $parts[1] ?? null;
|
||
// list($code, $recipient) = explode('_', $code);
|
||
$session = (object)Session::where('code', $code)->first()->toArray();
|
||
if (empty($session->feedback_link)) {
|
||
$forsms = ['road' => '1671763320-62ba6179-fb51-4350-bed3-bbc4e15f4391', 'casper' => '1752828215-ed1f07b7-6355-4ce0-88d6-8fb48cea62d1', 'casper_clinic' => '1671763322-62ba6179-fb51-4350-bed3-bbc4e15f4393', 'spirometry_simplified' => '1671763323-62ba6179-fb51-4350-bed3-bbc4e15f4394', 'APFT' => '1671763320-62ba6179-fb51-4350-bed3-bbc4e15f4391', 'casper_clinic_new' => '1723004438-58ea6609-6672-436a-97ad-681e5463d27d', 'casper_plus' => '1723004438-58ea6609-6672-436a-97ad-681e5463d27d', 'ecampus' => '1724666803-7c16a3f1-f294-4a4d-b068-0b829ecd8d37'];
|
||
$logos = ['road' => '/images/road-logo.jpg', 'casper' => '/casper/images/logo-left.png', 'casper_clinic' => '/casper_clinic/images/logo.png', 'spirometry_simplified' => '/spirometry_simplified/images/logo.png', 'APFT' => '/APFT/images/logo-left.png', 'casper_clinic_new' => '/casper_clinic_new/images/logo.png', 'casper_plus' => '/casper_plus/images/logo.png', 'ecampus' => '/ecampus/images/main-logo.png'];
|
||
$titles = ['road' => 'Refresher course on Obstructive Airways Diseases (ROAD)', 'casper' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER)', 'casper_clinic' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Clinics)', 'spirometry_simplified' => 'SPIROMETRY SIMPLIFIED', 'casper_clinic_new' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Clinics)', 'casper_plus' => 'Controlling Asthma in Pediatric Population through Education and Research (CASPER Plus)', 'ecampus' => 'Online COPD & Asthma Module for Post Graduate Students'];
|
||
|
||
$session->dates = json_decode($session->dates);
|
||
$forinfo = LambdaRequest::postrequest('form', 'survey/getrawform', ['partition' => 'rapport-crestroad', 'form_id' => $forsms[$session->type]], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
||
|
||
//echo '<pre>'; print_r($forinfo); exit;
|
||
|
||
$forinfo = $forinfo->data;
|
||
$request->session()->put('forinfo', $forinfo->form);
|
||
//echo '<pre>'; print_r($session); print_r($forinfo); exit;
|
||
$data = [
|
||
'session' => $session, 'questions' => $forinfo->questions, 'form' => $forinfo->form, 'form_id' => $forinfo->form->id,
|
||
'logo' => $logos[$session->type], 'title' => $titles[$session->type], 'recipient' => $recipient
|
||
];
|
||
|
||
if (\View::exists($session->type.'.feedbackform')) {
|
||
return view($session->type.'.feedbackform')->with($data);
|
||
} else {
|
||
return view('road.feedbackform')->with($data);
|
||
}
|
||
|
||
//return view('road.feedbackform')->with($data);
|
||
} else {
|
||
return redirect($session->feedback_link);
|
||
}
|
||
}
|
||
|
||
public function postpre_impact_assessment($code, Request $request)
|
||
{
|
||
$post = $request->except('_token');
|
||
$forinfo = $request->session()->get('forinfo');
|
||
$response = LambdaRequest::postrequest('contact', 'contact/update', ['id' => $post['recipient'], 'feedback' => 'yes', 'position' => 'india'], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
//echo '<pre>'; print_r($post); print_r($response); exit;
|
||
$finfo = LambdaRequest::postrequest('form', 'survey/submitform', ['formdata' => $post, 'entity_id' => $forinfo->id, 'partition' => 'rapport-crestroad', 'user_id' => '1658768001-5e2d6e6b-16c7-40b2-93c7-68bf55772ff3'], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
// dd($finfo);
|
||
//echo '<pre>'; print_r($forinfo); print_r(json_encode($post)); print_r($finfo); exit;
|
||
$session_code = $finfo->data->submission->formdata->session_code;
|
||
$recipient = $finfo->data->submission->formdata->recipient;
|
||
$logos = ['road' => '/images/road-logo.jpg', 'casper' => '/casper/images/logo-left.png', 'casper_clinic' => '/casper_clinic/images/logo.png', 'spirometry_simplified' => '/spirometry_simplified/images/logo.png', 'APFT' => '/APFT/images/logo-left.png', 'casper_clinic_new' => '/casper_clinic_new/images/logo.png', 'casper_plus' => '/casper_plus/images/logo.png', 'ecampus' => '/ecampus/images/logo.png'];
|
||
// echo '<pre>'; print_r($session_code); print_r($recipient); exit;
|
||
|
||
$session_type = DB::table('sessions')->where('code', $session_code)->pluck('type');
|
||
// return $session_type[0];
|
||
$logo = $logos[$session_type[0]];
|
||
|
||
return view('road.pre_impact_assessmentsuccess', compact('session_code', 'recipient', 'session_type', 'logo'));
|
||
|
||
//echo '<pre>'; print_r($finfo); print_r($post); print_r($forinfo); exit;
|
||
}
|
||
|
||
public function surveyform($code, Request $request)
|
||
{
|
||
$session = (object)Session::where('code', $code)->first()->toArray();
|
||
return redirect($session->survey_link);
|
||
}
|
||
|
||
public function certificate(Request $request)
|
||
{
|
||
$code = $request->input('code');
|
||
$session = Session::where('code', $code)->first();
|
||
$doctor = $request->input('doctor');
|
||
$response = LambdaRequest::getrequest('contact', 'contact/get_one', ['id' => $doctor], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
||
$doctor = $response->data->item;
|
||
//echo '<pre>'; print_r($doctor); exit;
|
||
$output = Creation::certificate($session, $doctor);
|
||
$filename = $output['filename'];
|
||
$folder = $output['folder'];
|
||
|
||
$headers = array('Content-Type: image/png',);
|
||
return Response::download($folder . '/' . $filename, 'certificate.png', $headers);
|
||
}
|
||
}
|