function order_print_time_class($orderid)
{
    $orderid = (int) $orderid;
    $ord = new order($orderid);
    $elapsed = orders_print_elapsed_time($ord);
    if ($elapsed < 1) {
        return '';
    }
    $level = 100 / CONF_COLOUR_PRINTED_MAX_TIME * $elapsed;
    $level = round($level, 0);
    if ($level > 255) {
        $level = 255;
    }
    if ($level < 0) {
        $level = 0;
    }
    $level = 255 - $level;
    $level = sprintf("%02x", $level);
    switch (strtolower(CONF_COLOUR_PRINTED_COLOUR)) {
        case 'red':
            $class = '#' . 'FF' . $level . $level;
            break;
        case 'green':
            $class = '#' . $level . 'FF' . $level;
            break;
        case 'blue':
            $class = '#' . $level . $level . 'FF';
            break;
        case 'magenta':
            $class = '#' . 'FF' . $level . 'FF';
            break;
        case 'cyan':
            $class = '#' . $level . 'FF' . 'FF';
            break;
        case 'yellow':
            $class = '#' . 'FF' . 'FF' . $level;
            break;
        case 'grey':
            $class = '#' . $level . $level . $level;
            break;
        default:
            $class = '#' . 'FF' . 'FF' . $level;
            break;
    }
    return $class;
}
    function table_row_pos($arr)
    {
        $output = '';
        $tbl = new table($arr['sourceid']);
        $toclose = $tbl->get('toclose');
        $dish = new dish($arr['dishid']);
        $dishname = $dish->name($_SESSION['language']);
        if (!$arr['deleted'] && $arr['printed'] != NULL && CONF_TIME_SINCE_PRINTED) {
            $ordid = (int) $arr['id'];
            $ord = new order($ordid);
            $dishname .= ' (' . orders_print_elapsed_time($ord, true) . ')';
            unset($ord);
        }
        $generic = $dish->get('generic');
        $deleted = $arr['deleted'];
        $orderid = $arr['id'];
        if ($arr['dishid'] == MOD_ID) {
            // first we clean the ingredient id from + and -
            $modingred = $arr['ingredid'];
            // then we find the ingredient name
            $ingr = new ingredient($modingred);
            $moddeddishname = $ingr->name($_SESSION['language']);
            // say if it's added or subtracted
            if ($arr['operation'] == 1) {
                $dishname = "" . ucfirst(phr('PLUS'));
            } elseif ($arr['operation'] == -1) {
                $dishname = "" . ucfirst(phr('MINUS'));
            } elseif ($arr['operation'] == 0) {
                $dishname = "";
            }
            // and finally consider any optional info (lot/few)
            if ($arr['ingred_qty'] == 1) {
                $dishname .= '<img src="' . IMAGE_PLUS . '" height="16" width="16" border="0">';
            } elseif ($arr['ingred_qty'] == -1) {
                $dishname .= '<img src="' . IMAGE_MINUS . '" height="16" width="16" border="0">';
            }
            $dishname .= " " . $moddeddishname;
            // gets the original ingred price (from ingreds table)
            // if the original price is 0 and the actual price is 0
            // then it means that the ingred has passed through the autocalc system
            // and we let the waiter know this, so he could check the prices.
            $modingredprice = $ingr->get('price');
            //$modingredprice=get_db_data(__FILE__,__LINE__,$_SESSION['common_db'],"ingreds","price",$modingred);
            if ($modingredprice == 0 && $arr['price'] != 0) {
                $dishname .= "(auto)";
            }
        }
        if ($arr['dishid'] == SERVICE_ID) {
            $dishname = ucfirst(phr('SERVICE_FEE'));
        }
        $classpriority = order_priority_class($arr['priority']);
        $oextra = order_extra_msg($arr['extra_care']);
        $class = order_printed_class($arr['printed'], $arr['suspend']);
        if (CONF_COLOUR_PRINTED && $arr['printed'] && !$arr['deleted']) {
            $classtime = order_print_time_class($arr['id']);
            if (!$classtime) {
                $classtime = $class;
            }
        } else {
            $classtime = $class;
        }
        $classextra = order_extra_class($arr['extra_care'], $class);
        // row begins
        $output .= '<tr>';
        // quantity cell
        if ($deleted && $arr['dishid'] != MOD_ID) {
            $output .= '<td><s>' . $arr['quantity'] . '</s></td>';
        } elseif (!$deleted && $arr['dishid'] != MOD_ID) {
            $output .= '<td><strong>' . $arr['quantity'] . '</strong></td>';
        } else {
            $output .= '<td>&nbsp;</td>';
        }
        // mods cell
        if ($deleted && $arr['dishid'] != MOD_ID) {
            $output .= '';
        } elseif (!$deleted && $arr['printed'] == NULL && $arr['dishid'] != MOD_ID && $arr['dishid'] != SERVICE_ID) {
            $link = 'orders.php?command=listmods&amp;data[id]=' . $arr['associated_id'];
        }
        // Name of the dish
        if ($deleted) {
            $output .= '<td><s>' . $dishname . '</s></td>';
        } else {
            if (!$deleted && $arr['printed'] == NULL && $arr['dishid'] != MOD_ID && $arr['dishid'] != SERVICE_ID) {
                $link = 'orders.php?command=listmods&amp;data[id]=' . $orderid;
                $output .= '
				<td onclick="loadModal(\'' . $link . '\');">' . $dishname . '</td>';
            } elseif (!$deleted && $arr['printed'] == NULL && $arr['dishid'] == MOD_ID) {
                $link = 'orders.php?command=listmods&amp;data[id]=' . $arr['associated_id'];
                $output .= '<td onclick="loadModal(\'' . $link . '\');">' . $dishname . '</td>';
            } else {
                $output .= '<td>' . $dishname . '</td>';
            }
        }
        if ($deleted) {
            $output .= '<td ><s>' . $oextra . '</s></td>';
        } else {
            $output .= '<td>' . $oextra . '</td>';
        }
        // priority cell
        $output .= '<td >' . $arr['priority'] . '</td>';
        // price cell
        $user = new user($_SESSION['userid']);
        if ($generic && $user->level[USER_BIT_CASHIER] && $arr['printed'] && !$deleted) {
            $link = 'orders.php?command=price_modify&amp;data[id]=' . $arr['id'];
            $output .= '<td onclick="redir(\'' . $link . '\');"><a href="' . $link . '">' . $arr['price'] . '</a></td>';
        } elseif ($deleted) {
            $output .= '<td><s>' . $arr['price'] . '</s></td>';
        } else {
            $output .= '<td >' . $arr['price'] . '</td>';
        }
        // edit button
        if ($toclose) {
            // the table has been closed, can't modify rows
            $output .= '<td>&nbsp;</td>';
        } elseif (!$deleted && $arr['printed'] != NULL && $arr['dishid'] != MOD_ID) {
            // printed orderd, special edit (only deleting or substiting)
            $link = 'orders.php?command=edit&amp;data[id]=' . $orderid;
        } elseif (!$deleted && $arr['dishid'] == MOD_ID) {
            // modification, can't edit directly, only via associated order
            $output .= '<td>&nbsp;</td>';
        } elseif ($deleted) {
            // deleted order, no editing, of course
            $output .= '<td>&nbsp;</td>';
        } else {
            // other cases, normal editing
            $link = 'orders.php?command=edit&data[id]=' . $orderid;
            $output .= '<td onclick="loadModal(\'' . $link . '\');"><img src="' . IMAGE_SOURCE . '" width="32" border="0"></a></td>';
        }
        // quantity arrows
        if ($toclose) {
            // table is closed, no more editing
            $output .= '<td>&nbsp;</td>';
        } else {
            // normal section to rapidly add or subtract single quantities
            $output .= '<td>';
            if (!$arr['printed'] && $arr['dishid'] != MOD_ID || $arr['dishid'] == SERVICE_ID) {
                $newquantity = $arr['quantity'] + 1;
                $link = "command=update&data[quantity]=" . $newquantity . "&data[id]=" . $orderid;
                if ($arr['suspend']) {
                    $link .= "&data[suspend]=1";
                }
                if ($arr['extra_care']) {
                    $link .= "&data[extra_care]=1";
                }
                $output .= '<a href="#" onClick="modifyDishQuantity(\'' . $link . '\')"><img src="' . IMAGE_PLUS . '" alt="' . ucfirst(phr('PLUS')) . ' (' . ucfirst(phr('ADD')) . ')" border=0></a></td><td>';
                if ($arr['quantity'] > 1) {
                    $newquantity = $arr['quantity'] - 1;
                    $link = "command=update&data[quantity]=" . $newquantity . "&data[id]=" . $orderid;
                    if ($arr['suspend']) {
                        $link .= "&data[suspend]=1";
                    }
                    if ($arr['extra_care']) {
                        $link .= "&data[extra_care]=1";
                    }
                    $output .= '<a href="#" onClick="modifyDishQuantity(\'' . $link . '\')"><img src="' . IMAGE_MINUS . '" alt="' . ucfirst(phr('MINUS')) . ' (' . ucfirst(phr('REMOVE')) . ')" border=0></a>';
                } elseif ($arr['quantity'] == 1 && CONF_ALLOW_EASY_DELETE) {
                    $newquantity = 0;
                    $link = "command=ask_delete&data[id]=" . $orderid;
                    if ($arr['suspend']) {
                        $link .= "&data[suspend]=1";
                    }
                    if ($arr['extra_care']) {
                        $link .= "data[extra_care]=1";
                    }
                    $output .= '<a href="#" onClick="modifyDishQuantity(\'' . $link . '\')"><img src="' . IMAGE_TRASH . '" width="32" alt="' . ucfirst(phr('MINUS')) . ' (' . ucfirst(phr('REMOVE')) . ')" border=0></a>';
                } else {
                    $output .= '&nbsp;' . "\n";
                }
            } else {
                $output .= '&nbsp;</td><td>&nbsp;';
            }
            $output .= '</td>';
        }
        $output .= '</tr>' . "\n\n";
        return $output;
    }