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++) {
             $part_id = isset($_REQUEST['id_' . $i]) ? (int) $_REQUEST['id_' . $i] : 0;
             try {
                 $part = new Part($database, $current_user, $log, $part_id);
                 $part->set_order_quantity($part->get_min_order_quantity());
             } catch (Exception $e) {
                 $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
    $all_orderdetails = $part->get_orderdetails();
} catch (Exception $e) {
    $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
    $fatal_error = true;
}
/********************************************************************************
 *
 *   Execute actions
 *
 *********************************************************************************/
if (!$fatal_error) {
    switch ($action) {
        case 'dec':
            // remove some parts
            try {
                $part->set_instock($part->get_instock() - abs($n_less));
                // reload the site without $_REQUEST['action'] to avoid multiple actions by manual refreshing
                header('Location: show_part_info.php?pid=' . $part_id);
            } catch (Exception $e) {
                $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
            }
            break;
        case 'inc':
            // add some parts
            try {
                $part->set_instock($part->get_instock() + abs($n_more));
                // reload the site without $_REQUEST['action'] to avoid multiple actions by manual refreshing
                header('Location: show_part_info.php?pid=' . $part_id);
            } catch (Exception $e) {
                $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
            }