<?php
// Installer helper: update existing tb_menu rows to point to the new laporan module
// Usage: open this file in browser (with DB accessible) or run via PHP-CLI then remove it after use.
require_once __DIR__ . '/../../lib/conn.php';

function run_update($conn, $oldUrl, $newUrl){
    $old = $conn->real_escape_string($oldUrl);
    $new = $conn->real_escape_string($newUrl);
    $sql = "UPDATE tb_menu SET url = '$new' WHERE url = '$old'";
    $res = $conn->query($sql);
    if($res){
        echo "Updated menu: $oldUrl -> $newUrl. Affected rows: " . $conn->affected_rows . "<br>";
    } else {
        echo "Failed to update $oldUrl: " . $conn->error . "<br>";
    }
}

echo '<h3>Installer: Update tb_menu to use mod=laporan</h3>';
run_update($conn, 'med.php?mod=daftar_pekerjaan', 'med.php?mod=laporan&act=daftar_pekerjaan');
run_update($conn, 'med.php?mod=omset', 'med.php?mod=laporan&act=omset');
run_update($conn, 'med.php?mod=penyelesaian_pekerjaan', 'med.php?mod=laporan&act=penyelesaian');
run_update($conn, 'med.php?mod=pemakaian', 'med.php?mod=laporan&act=pemakaian');
run_update($conn, 'med.php?mod=laporan_kerja_harian', 'med.php?mod=laporan&act=penyelesaian');

echo '<p>Done. Please verify your menu in the application. Remove this file after use.</p>';
