/********************************************************************************
 *
 *   Execute actions
 *
 *********************************************************************************/
if (!$fatal_error) {
    switch ($action) {
        case 'apply_changes':
            // save new "selected_supplier" + "order_quantity", and delete or change "instock"
            for ($i = 0; $i < $table_rowcount; $i++) {
                $part_id = isset($_REQUEST['id_' . $i]) ? (int) $_REQUEST['id_' . $i] : 0;
                $order_orderdetails_id = isset($_REQUEST['orderdetails_' . $i]) ? (int) $_REQUEST['orderdetails_' . $i] : 0;
                $order_quantity = isset($_REQUEST['order_quantity_' . $i]) ? max(0, (int) $_REQUEST['order_quantity_' . $i]) : 0;
                try {
                    $part = new Part($database, $current_user, $log, $part_id);
                    $part->set_order_orderdetails_id($order_orderdetails_id);
                    $part->set_order_quantity($order_quantity);
                    if (isset($_REQUEST['remove_' . $i]) && $part->get_manual_order()) {
                        $part->set_manual_order(false);
                    }
                    if (isset($_REQUEST['tostock_' . $i])) {
                        $part->set_instock($part->get_instock() + $order_quantity);
                    }
                } catch (Exception $e) {
                    $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
                }
            }
            $reload_site = true;
            break;
        case 'autoset_quantities':
            for ($i = 0; $i < $table_rowcount; $i++) {