diff --git a/app/Http/Controllers/NeblogisticreportController.php b/app/Http/Controllers/NeblogisticreportController.php index 36c9ea6c..84ce6d0b 100644 --- a/app/Http/Controllers/NeblogisticreportController.php +++ b/app/Http/Controllers/NeblogisticreportController.php @@ -485,38 +485,54 @@ class NeblogisticreportController extends Controller $data = DB::table('neblogistic')->where('id', $params['record_id'])->first(); - + $emailWarnings = []; + if (isset($params['status'])) { if ($params['status'] == 'Rejected') { - - Mail::to($data->emp_email) - ->cc($data->abm_email) - ->send(new NeblogisticRejection((array)$data)); - Mail::to('ravigulhane1983@gmail.com')->send(new NeblogisticRejection((array)$data)); - - } - elseif (in_array($params['status'], ['Dispatched', 'Delivered'], true)) { + $rejectWarn = $this->sendNeblogisticMailSafely( + new NeblogisticRejection((array) $data), + $data->emp_email ?? null, + $data->abm_email ?? null, + ['id' => $data->id ?? null, 'mail' => 'rejection'] + ); + if ($rejectWarn !== null) { + $emailWarnings[] = $rejectWarn; + } + try { + Mail::to('ravigulhane1983@gmail.com')->send(new NeblogisticRejection((array) $data)); + } catch (\Throwable $e) { + Log::error('Neblogistic rejection debug email failed', [ + 'id' => $data->id ?? null, + 'message' => $e->getMessage(), + ]); + } + } elseif (in_array($params['status'], ['Dispatched', 'Delivered'], true)) { Log::info('Neblogistic status update email', [ 'data' => $data, ]); - // Send to TM (emp_email) - if (!empty($data->emp_email)) { - Mail::to($data->emp_email) - ->send(new NeblogisticStatusUpdate((array)$data, 'tm')); + $tmWarn = $this->sendNeblogisticMailSafely( + new NeblogisticStatusUpdate((array) $data, 'tm'), + $data->emp_email ?? null, + null, + ['id' => $data->id ?? null, 'mail' => 'status_tm'] + ); + if ($tmWarn !== null) { + $emailWarnings[] = $tmWarn; } - - // Send to ABM (abm_email) - if (!empty($data->abm_email)) { - Mail::to($data->abm_email) - ->send(new NeblogisticStatusUpdate((array)$data, 'abm')); + $abmWarn = $this->sendNeblogisticMailSafely( + new NeblogisticStatusUpdate((array) $data, 'abm'), + $data->abm_email ?? null, + null, + ['id' => $data->id ?? null, 'mail' => 'status_abm'] + ); + if ($abmWarn !== null) { + $emailWarnings[] = $abmWarn; } // Prevent cron from re-sending the same status email DB::table('neblogistic') ->where('id', $params['record_id']) ->update(['status_email_sent' => $params['status']]); - } else { - } } @@ -529,15 +545,22 @@ class NeblogisticreportController extends Controller $data->pin_code = $data->address_pin_code; $data->clinic_hospital_home_name = $data->clinic_hospital_name; - Mail::to($data->emp_email) - ->cc($data->abm_email) - ->send(new Neblogistic((array)$data)); + $editWarn = $this->sendNeblogisticMailSafely( + new Neblogistic((array) $data), + $data->emp_email ?? null, + $data->abm_email ?? null, + ['id' => $data->id ?? null, 'mail' => 'edit_notification'] + ); + if ($editWarn !== null) { + $emailWarnings[] = $editWarn; + } //Mail::to('arbaz@stratawiz.com')->send(new NeblogisticSupervisor((array)$data)); $user = Auth::user(); - - // echo "
";
-        // print_r($params);
+        $successMessage = 'Data Saved';
+        if (!empty($emailWarnings)) {
+            $successMessage .= '. ' . implode(' ', array_unique($emailWarnings));
+        }
 
         if(!$params['submission_id'] == ''){
         // return print_r($params);
@@ -546,7 +569,7 @@ class NeblogisticreportController extends Controller
             $history = LambdaRequest::signedrequest('post', 'form', 'formentity/submitform', $post, 120);
             Log::info('formsubmission after edit', [ 'history' => $history]);
             if ($history->status === 'success') {
-                return redirect()->back()->with('message', 'Data Saved');
+                return redirect()->back()->with('message', $successMessage);
             } else {
                 return redirect()->back()->with('error', 'Operation failed.');
             }
@@ -557,7 +580,7 @@ class NeblogisticreportController extends Controller
 
 
         if ($dataUpdate) {
-            return redirect()->back()->with('message', 'Data Saved');
+            return redirect()->back()->with('message', $successMessage);
         } else {
             return redirect()->back()->with('error', 'Operation failed.');
         }
@@ -2048,6 +2071,76 @@ class NeblogisticreportController extends Controller
         return is_object($response) && ($response->status ?? '') === 'success';
     }
 
+    /**
+     * True when value is a real mailbox (rejects empty / Vacant placeholders).
+     */
+    protected function isValidNeblogisticEmail($email): bool
+    {
+        $email = trim((string) $email);
+        if ($email === '' || stripos($email, 'vacant') !== false) {
+            return false;
+        }
+        return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
+    }
+
+    /**
+     * Send a mailable without letting invalid Vacant/CC addresses 500 the request.
+     * Returns a short user-facing warning, or null when send succeeded / nothing to warn.
+     *
+     * @param  mixed  $mailable
+     * @param  string|null  $to
+     * @param  string|null  $cc
+     * @param  array  $context
+     */
+    protected function sendNeblogisticMailSafely($mailable, $to, $cc = null, array $context = []): ?string
+    {
+        $validTo = $this->isValidNeblogisticEmail($to) ? trim((string) $to) : null;
+        $validCc = $this->isValidNeblogisticEmail($cc) ? trim((string) $cc) : null;
+        $warnings = [];
+
+        if ($to !== null && trim((string) $to) !== '' && $validTo === null) {
+            $warnings[] = 'Notification email was not sent because the recipient email is missing or invalid (e.g. Vacant).';
+            Log::warning('Neblogistic email skipped: invalid to address', $context + [
+                'to' => $to,
+                'cc' => $cc,
+            ]);
+        } elseif ($cc !== null && trim((string) $cc) !== '' && $validCc === null) {
+            $warnings[] = 'ABM notification was skipped because the ABM email is missing or invalid (e.g. Vacant).';
+            Log::warning('Neblogistic email CC skipped: invalid cc address', $context + [
+                'to' => $to,
+                'cc' => $cc,
+            ]);
+        }
+
+        if ($validTo === null) {
+            return $warnings[0] ?? 'Notification email was not sent because no valid recipient email was found.';
+        }
+
+        try {
+            $pending = Mail::to($validTo);
+            if ($validCc !== null) {
+                $pending->cc($validCc);
+            }
+            $pending->send($mailable);
+        } catch (\Swift_RfcComplianceException $e) {
+            Log::error('Neblogistic email RFC error', $context + [
+                'to' => $validTo,
+                'cc' => $validCc,
+                'message' => $e->getMessage(),
+            ]);
+            return 'Notification email could not be sent due to an invalid email address.';
+        } catch (\Throwable $e) {
+            Log::error('Neblogistic email failed', $context + [
+                'to' => $validTo,
+                'cc' => $validCc,
+                'message' => $e->getMessage(),
+            ]);
+            return 'Notification email could not be sent.';
+        }
+
+        return $warnings[0] ?? null;
+    }
+
     protected function normalizeNapPartition(?string $partition): string
     {
         $partition = trim((string) $partition);
diff --git a/database/sql/incept_neb_allocations_update_2026-10-28_aravind_m.sql b/database/sql/incept_neb_allocations_update_2026-10-28_aravind_m.sql
new file mode 100644
index 00000000..8a81bf64
--- /dev/null
+++ b/database/sql/incept_neb_allocations_update_2026-10-28_aravind_m.sql
@@ -0,0 +1,92 @@
+-- Nebulizers Allocation Data - 28102026 ARAVIND M.xlsx
+-- UPDATE incept_neb_allocations for 28 employees (sheet under ARAVIND M).
+-- Existing incept_neb_usage rows are left untouched.
+-- 27 rows differ from current DB (mostly control_d_qty); 144137 ARAVIND M unchanged.
+-- Sheet totals: Robust 332, Mini 395, Control D 319.
+START TRANSACTION;
+
+-- 144137 / ARAVIND M  Robust 11, Mini 5, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'ARAVIND M', designation = 'Area Business Manager', team = 'Neb - Arise', robust_qty = 11, mini_qty = 5, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '144137';
+
+-- 179234 / Harish Kumar  Robust 0, Mini 10, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Harish Kumar', designation = 'Therapy Manager', team = 'Neb - Arise', robust_qty = 0, mini_qty = 10, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '179234';
+
+-- 147085 / Paladi Vikas  Robust 11, Mini 15, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Paladi Vikas', designation = 'Therapy Manager', team = 'Neb 1', robust_qty = 11, mini_qty = 15, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '147085';
+
+-- 149522 / Banty .  Robust 11, Mini 15, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Banty .', designation = 'Therapy Manager', team = 'Neb 1', robust_qty = 11, mini_qty = 15, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '149522';
+
+-- 173569 / Raghav Tiwari  Robust 11, Mini 15, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Raghav Tiwari', designation = 'Therapy Manager', team = 'Neb 1', robust_qty = 11, mini_qty = 15, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '173569';
+
+-- 176198 / Enukonda Vishwanth  Robust 11, Mini 15, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Enukonda Vishwanth', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '176198';
+
+-- 165632 / Aashi Gupta  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Aashi Gupta', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '165632';
+
+-- 168436 / Ashish Singh Chauhan  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Ashish Singh Chauhan', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '168436';
+
+-- 169088 / Bharti Rajput  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Bharti Rajput', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '169088';
+
+-- 169431 / Anamika Anni Shukla  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Anamika Anni Shukla', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '169431';
+
+-- 170212 / Upender Yadav  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Upender Yadav', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '170212';
+
+-- 170214 / Priyanshi Sharma  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Priyanshi Sharma', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '170214';
+
+-- 170282 / Parshant Mavi  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Parshant Mavi', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '170282';
+
+-- 171898 / Priyanshu Pandey  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Priyanshu Pandey', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '171898';
+
+-- 172432 / Aditya Joshi  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Aditya Joshi', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '172432';
+
+-- 176201 / Deepali shrivastav  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Deepali shrivastav', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '176201';
+
+-- 177311 / Sakshi Kanojia  Robust 6, Mini 10, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Sakshi Kanojia', designation = 'Management Trainee', team = 'Neb 2', robust_qty = 6, mini_qty = 10, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '177311';
+
+-- 127020 / Pawan Panwar  Robust 16, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Pawan Panwar', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 16, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '127020';
+
+-- 129394 / Rakesh Kumar  Robust 26, Mini 15, Control D 13
+UPDATE incept_neb_allocations SET emp_name = 'Rakesh Kumar', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 26, mini_qty = 15, control_d_qty = 13, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '129394';
+
+-- 139813 / Rohit Dhall  Robust 24, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Rohit Dhall', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 24, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '139813';
+
+-- 156360 / Akash Kumar Bharti  Robust 11, Mini 15, Control D 13
+UPDATE incept_neb_allocations SET emp_name = 'Akash Kumar Bharti', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 13, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '156360';
+
+-- 159248 / Ashok Kumar  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Ashok Kumar', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '159248';
+
+-- 161573 / Amandeep .  Robust 21, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Amandeep .', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 21, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '161573';
+
+-- 165238 / Ankit .  Robust 19, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Ankit .', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 19, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '165238';
+
+-- 172211 / Punit Bhardwaj  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Punit Bhardwaj', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '172211';
+
+-- 172442 / Sanjana Kumari  Robust 11, Mini 15, Control D 10
+UPDATE incept_neb_allocations SET emp_name = 'Sanjana Kumari', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 10, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '172442';
+
+-- 174034 / Nandan .  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Nandan .', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '174034';
+
+-- 178614 / Digvijay Sagar  Robust 0, Mini 10, Control D 13
+UPDATE incept_neb_allocations SET emp_name = 'Digvijay Sagar', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 0, mini_qty = 10, control_d_qty = 13, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '178614';
+
+COMMIT;
diff --git a/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d-history.blade.php b/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d-history.blade.php
new file mode 100644
index 00000000..ef9237c2
--- /dev/null
+++ b/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d-history.blade.php
@@ -0,0 +1,148 @@
+
+
+
+    @include('layouts.shared/title-meta', ['title' => "History"])
+    @include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? ''])
+
+
+
+    
+
+ + +
+
+

{{$formname}}

+
+ +
+ + @if(session()->has('message')) +
+ {{ session()->get('message') }} +
+ @endif + @if(session()->has('error')) +
+ {{ session()->get('error') }} +
+ @endif +
+
+
+
+
+
+
+ + + + + @foreach(($userAttrs ?? []) as $attr) + + @endforeach + @foreach($questions as $code => $question) + @if($question->type == 'hidden') + @continue; + @endif + @if($question->type == 'multitextbox') + @foreach($question->options as $k => $v) + + @endforeach + @else + + @endif + @endforeach + + + + + @foreach($submissions as $submission) + + + @foreach(($userAttrs ?? []) as $attr) + @php + $uaUser = $submission->user_info ?? null; + $uaVal = '-'; + if ($uaUser) { + if (isset($uaUser->{$attr}) && $uaUser->{$attr} !== '') { + $uaVal = $uaUser->{$attr}; + } elseif (isset($uaUser->{'attribute_'.$attr}) && $uaUser->{'attribute_'.$attr} !== '') { + $uaVal = $uaUser->{'attribute_'.$attr}; + } + } + @endphp + + @endforeach + @foreach($questions as $code => $question) + @if($question->type == 'hidden') + @continue; + @endif + @if($question->type == 'file') + + + @elseif($question->type == 'radiometrix' && isset($submission->formdata->{$code}) && is_object($submission->formdata->{$code})) + + + @elseif($question->type == 'multitextbox') + @foreach($question->options as $k => $v) + @php + $optKey = is_object($v) ? ($v->value ?? $k) : $k; + $optVal = ''; + if (isset($submission->formdata->{$optKey})) { + $raw = $submission->formdata->{$optKey}; + $optVal = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw); + } elseif (isset($submission->formdata->{$code}) && (is_object($submission->formdata->{$code}) || is_array($submission->formdata->{$code}))) { + $box = (array) $submission->formdata->{$code}; + if (array_key_exists($optKey, $box)) { + $raw = $box[$optKey]; + $optVal = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw); + } + } + @endphp + + @endforeach + + @elseif(count((array)$question->options) > 0 && 1==2 ) + + @else + + @endif + @endforeach + + + @endforeach + +
Submission Date{{ $userAttrLabels[$attr] ?? ucwords(str_replace('_', ' ', $attr)) }}{{ is_object($v) ? ($v->display ?? $v->label ?? $k) : $v }} ({{$question->label}}){{$question->label}}Action
{{date("d M Y", strtotime($submission->updatedAt))}}{{ $uaVal }} Download + {{ collect((array)$submission->formdata->{$code})->map(function($val, $key){ return "$key: $val"; })->implode(', ') }} + {{ $optVal }}{{ $question->options->{ $submission->formdata->{$code} } }}{{ isset($submission->formdata->{$code}) ? is_array($submission->formdata->{$code})? implode(', ', $submission->formdata->{$code}) : (is_object($submission->formdata->{$code}) ? collect((array)$submission->formdata->{$code})->map(function($val, $key){ return "$key: $val"; })->implode(', ') : $submission->formdata->{$code}) : '' }} + @php + $isApproved = ($submission->workflow ?? '') == 'yes' && ($submission->workflow_status ?? '') == 'approved'; + $showFieldDelete = isset($form->allow_delete_by_user) && $form->allow_delete_by_user == 'yes' && !$isApproved; + @endphp + @if($isApproved) +

Approved

+ @endif + @if($showFieldDelete || !empty($can_delete_submission)) + Delete + @endif +
+
+ +
+
+ +
+
+
+
+ +
+ +
+ + @include('layouts.shared/footer-script') + + \ No newline at end of file diff --git a/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d.blade.php b/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d.blade.php index 25cc6f01..be503ff7 100644 --- a/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d.blade.php +++ b/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d.blade.php @@ -44,7 +44,12 @@ @if($id) @endif - @if(isset($form->manager_can_submit) && $form->manager_can_submit == true) + + @if( + isset($form->manager_can_submit) && + $form->manager_can_submit == true && + $form->title != 'Upload Daily Field Work Photo' + )
@@ -147,13 +157,24 @@ @break @case('file') - @if(!isset($form->is_approval) || $form->is_approval != 'yes') - + @if(!isset($form->is_approval) || $form->is_approval != 'yes') @if($question->code == 'upload_photo') + +
+ + + +
+
@@ -169,22 +190,18 @@ style="display:none;">
- -
+ @else required == 'yes' ? 'required' : ''}}> @endif - @elseif(isset($question->value)) - - @endif - @break + @elseif(isset($question->value)) + + @endif + @break @case('multitextbox')
@@ -381,29 +398,59 @@ $('#start-photo-camera').on('click', async function () { try { - if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) { - throw new Error('Camera access is not supported by this browser.'); + if (!navigator.mediaDevices || + !navigator.mediaDevices.getUserMedia) { + throw new Error('Camera API is unavailable. Use HTTPS or localhost.'); } + // Request camera permission photoStream = await navigator.mediaDevices.getUserMedia({ - video: { facingMode: { ideal: 'environment' } }, + video: { + facingMode: { ideal: 'environment' } + }, audio: false }); + // Check required elements + if (!video || !preview || !photoInput) { + throw new Error('Camera elements are missing from the page.'); + } + video.srcObject = photoStream; video.style.display = 'block'; preview.style.display = 'none'; + await video.play(); + $('#start-photo-camera').hide(); $('#capture-photo').show(); $('#retake-photo').hide(); } catch (error) { - Swal.fire({ - icon: 'error', - title: 'Camera Unavailable', - text: 'Please allow camera access and try again.' - }); + console.error('Camera error:', error); + + // Stop any partially opened camera stream + if (photoStream) { + photoStream.getTracks().forEach(track => track.stop()); + photoStream = null; + } + + if (error.name === 'NotAllowedError' || + error.name === 'PermissionDeniedError') { + + Swal.fire({ + icon: 'warning', + title: 'Camera Access Denied', + text: 'Please enable camera permission for this website in your browser settings, then try again.' + }); + + } else { + Swal.fire({ + icon: 'error', + title: 'Unable to Open Camera', + text: error.message || 'Please check your camera and try again.' + }); + } } }); diff --git a/resources/views/form/rapport-lifemankind/preview-1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php b/resources/views/form/rapport-lifemankind/preview-1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php index 2b447580..05c39e2b 100644 --- a/resources/views/form/rapport-lifemankind/preview-1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php +++ b/resources/views/form/rapport-lifemankind/preview-1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php @@ -1,311 +1,176 @@ - @include('layouts.shared/title-meta', ['title' => "Form"]) - @include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? '']) - + @include('layouts.shared/title-meta', ['title' => $form->title ?? 'TGICS']) + @include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? '']) + -
- processing... -
- - - - -@include('layouts.shared/footer-script') - - + - - \ No newline at end of file +