Files
Thanakorn SandClaude Sonnet 4.6 b07882e3f4 code audit fixes: require_once, issue flow, role guards
- Upgraded all plain `require` to `require_once` across 172 api/engine
  and api/engine_report files to prevent class-redeclaration errors
- Added issue button, issue_invoice() with GL toastr, and delete_invoice()
  to expense/manage_purchase_invoice.php, bringing it in line with
  po/manage_purchase_invoice.php
- Added can_delete role guard (admin/owner only) to trash icons on
  revenue/invoice.php and expense/purchase_invoice.php, matching the
  existing pattern in finance/receipt.php and finance/payment.php

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-23 17:06:08 +07:00

54 lines
2.1 KiB
PHP

<?php
session_start();
require_once '../../../assets/utils/db_auth.php';
require_once '../../../assets/utils/classes/FileUploader.php';
require_once '../../../assets/utils/classes/UserManager.php';
try {
$um = new UserManager($pdo1, $company_id, $user_id);
// ── Fetch current picture filename from DB ────────────────
$current_picture = $um->getProfilePicture();
// ── Handle new picture upload ─────────────────────────────
$db_picture = $current_picture;
if (!empty($_FILES['profile_picture']['name'])) {
// Remove old file if exists
if (!empty($current_picture)) {
$old_path = $include_url . 'uploads/profile/' . $current_picture;
if (file_exists($old_path)) unlink($old_path);
}
$uploader = new FileUploader($include_url . 'uploads/profile/');
$errors = $uploader->upload('profile_picture');
if (!empty($errors)) {
$answer['message'] = $errors[0];
http_response_code(400);
exit(json_encode($answer));
}
$db_picture = $uploader->getUploadedFiles()[0] ?? '';
}
// ── Update user record ────────────────────────────────────
$um->updateProfile($data, $db_picture);
// ── Refresh session ───────────────────────────────────────
$_SESSION['login_name'] = trim($data['name'] ?? '');
$_SESSION['login_surname'] = trim($data['surname'] ?? '');
$_SESSION['login_profile_picture'] = $db_picture;
$answer['success'] = 1;
$answer['message'] = 'Profile updated successfully.';
$answer['profile_picture'] = $db_picture;
} catch (Exception $e) {
$answer['message'] = 'Failed to update profile.';
http_response_code(500);
}
exit(json_encode($answer));