File manager - Edit - /home/webtrixia/.trash/debug.php
Back
<?php define('ROOT', __DIR__); ini_set('display_errors', 1); error_reporting(E_ALL); require ROOT.'/config/config.php'; require ROOT.'/src/helpers/Core.php'; require ROOT.'/src/controllers/controllers.php'; session_start(); $user = Auth::user(); $action = $_GET['a'] ?? 'menu'; // Generate CSRF for tests if(empty($_SESSION['csrf'])) $_SESSION['csrf'] = bin2hex(random_bytes(16)); $csrf = $_SESSION['csrf']; header('Content-Type: text/html; charset=utf-8'); echo '<style>body{font-family:sans-serif;padding:20px} pre{background:#f5f5f5;padding:12px;border-radius:6px} h3{color:#1A6FF5}</style>'; if($action === 'menu'){ echo '<h2>VETTA Debug</h2>'; echo '<p><b>User:</b> '.($user ? $user->name.' ('.$user->role.')' : '<span style="color:red">NOT LOGGED IN - <a href="/login">Login first</a></span>').'</p>'; if($user){ echo '<ul>'; echo '<li><a href="?a=health">Test Health Save</a></li>'; echo '<li><a href="?a=card">Test Card Activate</a></li>'; echo '<li><a href="?a=records">Test Add Record (vet/clinic only)</a></li>'; echo '<li><a href="?a=slots">Test Slots</a></li>'; echo '</ul>'; } } if(!$user && $action !== 'menu'){ echo '<p style="color:red">Please <a href="/login">login first</a>, then come back here.</p>'; exit; } if($action === 'health'){ echo '<h3>Test Health Save</h3><pre>'; $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS); $pet = $pdo->query("SELECT id, name FROM pets WHERE owner_id={$user->id} LIMIT 1")->fetch(PDO::FETCH_ASSOC); echo "Pet: ".json_encode($pet)."\n"; if(!$pet){ echo "No pets found!\n"; exit; } $_POST = ['pet_id'=>$pet['id'],'food_brand'=>'Royal Canin Test','food_notes'=>'debug','likes'=>'Пиле','dislikes'=>'Лук','allergies'=>'','conditions'=>'','medications'=>'','csrf'=>$csrf]; $_SESSION['csrf_verified'] = false; // bypass CSRF for test // Patch CSRF try { $result = Pets::saveHealth(); echo "Result: ".json_encode($result, JSON_UNESCAPED_UNICODE)."\n"; } catch(Exception $e){ echo "ERROR: ".$e->getMessage()." at line ".$e->getLine()."\n"; echo $e->getTraceAsString()."\n"; } echo '</pre>'; } if($action === 'card'){ echo '<h3>Test Card Activate</h3><pre>'; $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS); $card = $pdo->query("SELECT code FROM cards WHERE status='unused' LIMIT 1")->fetch(PDO::FETCH_ASSOC); echo "Available card: ".json_encode($card)."\n"; echo "Current user premium_until: ".($user->premium_until ?? 'null')."\n\n"; if($card){ // Test directly without CSRF $pdo->prepare("UPDATE users SET premium_until=NULL WHERE id=?")->execute([$user->id]); $base = date('Y-m-d'); $months = 1; $until = date('Y-m-d', strtotime("+{$months} months", strtotime($base))); echo "Would set premium until: $until\n"; // Check if subscriptions table exists try { $pdo->query("SELECT 1 FROM subscriptions LIMIT 1"); echo "subscriptions table: OK\n"; } catch(Exception $e){ echo "subscriptions table: MISSING - ".$e->getMessage()."\n"; } // Try the actual activation $_POST = ['code'=>$card['code'],'csrf'=>$csrf]; try { $result = Cards::activate(); echo "Result: ".json_encode($result, JSON_UNESCAPED_UNICODE)."\n"; } catch(Exception $e){ echo "ERROR: ".$e->getMessage()." at line ".$e->getLine()."\n"; } } echo '</pre>'; } if($action === 'slots'){ echo '<h3>Slots test</h3><pre>'; $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS); $clinics = $pdo->query("SELECT id, name FROM clinics")->fetchAll(PDO::FETCH_ASSOC); $dates = [date('Y-m-d'), date('Y-m-d', strtotime('next monday')), date('Y-m-d', strtotime('+1 day'))]; foreach($dates as $date){ echo "\nDate: $date (dow=".date('w', strtotime($date)).")\n"; foreach($clinics as $c){ $_GET['clinic_id'] = $c['id']; $_GET['date'] = $date; $r = Appointments::slots(); $cnt = count($r['slots']??[]); $closed = $r['closed']??false; echo " Clinic {$c['id']} ({$c['name']}): ".($closed?"CLOSED":"$cnt slots")."\n"; } } echo '</pre>'; } if($action === 'records'){ echo '<h3>Test Add Record</h3><pre>'; $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS); $cu = $pdo->prepare("SELECT cu.*, c.name as clinic_name FROM clinic_users cu JOIN clinics c ON c.id=cu.clinic_id WHERE cu.user_id=?"); $cu->execute([$user->id]); $cu_row = $cu->fetch(PDO::FETCH_ASSOC); echo "Role: {$user->role}\nClinic: ".json_encode($cu_row)."\n\n"; if(!$cu_row){ echo "User is not a vet/clinic admin!\n"; exit; } $pet = $pdo->prepare("SELECT p.id, p.name FROM pets p JOIN access_grants ag ON ag.pet_id=p.id WHERE ag.clinic_id=? LIMIT 1"); $pet->execute([$cu_row['clinic_id']]); $pet_row = $pet->fetch(PDO::FETCH_ASSOC); echo "Pet to add record to: ".json_encode($pet_row)."\n"; if($pet_row){ $_POST = ['pet_id'=>$pet_row['id'],'record_type'=>'checkup','title'=>'Debug Test','visit_date'=>date('Y-m-d H:i:s'),'csrf'=>$csrf]; try { $result = Records::store(); echo "Result: ".json_encode($result, JSON_UNESCAPED_UNICODE)."\n"; } catch(Exception $e){ echo "ERROR: ".$e->getMessage()." at ".$e->getLine()."\n"; } } echo '</pre>'; }
| ver. 1.4 |
Github
|
.
| PHP 8.2.31 | Generation time: 0 |
proxy
|
phpinfo
|
Settings