<?php

use Illuminate\Support\Facades\DB;

$path = "../../../";
require_once $path . "core/includes/header.inc.php";

if ($_REQUEST['action'] == "order") {

    $table_name = preg_replace('/[^a-z0-9_]/i', '', $_REQUEST['table']);
    $order_column = preg_replace('/[^a-z0-9_]/i', '', $_REQUEST['field']);

    if (!empty($_REQUEST['rorder']) && !empty($table_name) && !empty($order_column)) {

        foreach ($_REQUEST['rorder'] as $order => $record) {
            DB::table($table_name)
                ->where('id', $record)
                ->update([
                    $order_column => $order
                ]);
        }
    }
}
