function create_from_external($obj_id, $obj_type)
 {
     if ($obj_type == TYPE_DISH) {
         $obj = new dish($obj_id);
         foreach ($obj->ingredients() as $ingredid) {
             $err = $this->create_from_external($ingredid, TYPE_INGREDIENT);
             if ($err && $err != ERR_OBJECT_ALREADY_EXISTS) {
                 return $err;
             }
         }
         foreach ($obj->dispingredients() as $ingredid) {
             $err = $this->create_from_external($ingredid, TYPE_INGREDIENT);
             if ($err && $err != ERR_OBJECT_ALREADY_EXISTS) {
                 return $err;
             }
         }
     } elseif ($obj_type == TYPE_INGREDIENT) {
         $obj = new ingredient($obj_id);
     } else {
         return ERR_NO_TYPE_SPECIFIED;
     }
     if ($this->find_external($obj_id, $obj_type)) {
         return ERR_OBJECT_ALREADY_EXISTS;
     }
     $input_data['name'] = $obj->name();
     $input_data['ref_type'] = $obj_type;
     $input_data['ref_id'] = $obj_id;
     $err = $this->insert($input_data);
     return $err;
 }
 function list_rows($arr, $row)
 {
     global $tpl;
     global $display;
     $col = 0;
     if (!$this->disable_mass_delete) {
         $display->rows[$row][$col] = '<input type="checkbox" name="delete[]" value="' . $arr['id'] . '">';
         $display->width[$row][$col] = '1%';
         $col++;
     }
     foreach ($arr as $field => $value) {
         if (isset($this->allow_single_update) && in_array($field, $this->allow_single_update)) {
             $link = $this->link_base . '&amp;command=update_field&amp;data[id]=' . $arr['id'] . '&amp;data[field]=' . $field;
             if ($this->limit_start) {
                 $link .= '&amp;data[limit_start]=' . $this->limit_start;
             }
             if ($this->orderby) {
                 $link .= '&amp;data[orderby]=' . $this->orderby;
             }
             if ($this->sort) {
                 $link .= '&amp;data[sort]=' . $this->sort;
             }
             $display->links[$row][$col] = $link;
         } elseif (method_exists($this, 'form')) {
             $link = $this->file . '?class=' . get_class($this) . '&amp;command=edit&amp;data[id]=' . $arr['id'];
         } else {
             $link = '';
         }
         if ($field == 'name' && CONF_SHOW_SUMMARY_ON_LIST) {
             $dish = new dish($arr['id']);
             $value .= '<span class="admin_ingreds_list">';
             $ingreds = $dish->ingredients_names();
             if (!empty($ingreds) && is_array($ingreds)) {
                 $value .= '<br/>' . ucphr('INCLUDED') . ': ';
                 foreach ($ingreds as $key2 => $value2) {
                     $value .= ucfirst($value2) . ", ";
                 }
                 $value = substr($value, 0, -2);
                 $value .= '';
             }
             $ingreds = $dish->dispingredients_names();
             if (!empty($ingreds) && is_array($ingreds)) {
                 $value .= '<br/>' . ucphr('AVAILABLE') . ': ';
                 foreach ($ingreds as $key2 => $value2) {
                     $value .= ucfirst($value2) . ", ";
                 }
                 $value = substr($value, 0, -2);
                 $value .= '';
             }
             $value .= '</span>';
         }
         $display->rows[$row][$col] = $value;
         if ($link && $field == 'name') {
             $display->links[$row][$col] = $link;
         }
         if ($link) {
             $display->clicks[$row][$col] = 'redir(\'' . $link . '\');';
         }
         $col++;
     }
 }
 function find_connected_dishes($show_deleted = false, $link = false)
 {
     $output = array();
     $query = "SELECT dishes.id, dishes.table_id, dishes.table_name FROM `dishes`";
     $query .= " JOIN `dishes` WHERE dishes.table_id=dishes.id";
     $query .= " AND (`ingreds` LIKE '% " . $this->id . " %'";
     $query .= " OR `ingreds` LIKE '" . $this->id . " %'";
     $query .= " OR `ingreds` LIKE '" . $this->id . "'";
     $query .= " OR `ingreds` LIKE '% " . $this->id . "')";
     if (!$show_deleted) {
         $query .= " AND dishes.deleted='0'";
     }
     $query .= " ORDER BY dishes.table_name ASC";
     $res = common_query($query, __FILE__, __LINE__);
     if (!$res) {
         return ERR_MYSQL;
     }
     while ($arr = mysql_fetch_array($res)) {
         $dish = new dish($arr['id']);
         $tmp = '';
         if ($link) {
             $tmp .= '<a href="' . $this->file . '?class=dish&command=edit&data[id]=' . $dish->id . '">';
         }
         $tmp .= $dish->name($_SESSION['language']);
         if ($link) {
             $tmp .= '</a>';
         }
         $output['included'][$dish->id] = $tmp;
     }
     $query = "SELECT dishes.id, dishes.table_id, dishes.table_name FROM `dishes`";
     $query .= " JOIN `dishes` WHERE table_id=dishes.id";
     $query .= " AND (`dispingreds` LIKE '% " . $this->id . " %'";
     $query .= " OR `dispingreds` LIKE '" . $this->id . " %'";
     $query .= " OR `dispingreds` LIKE '" . $this->id . "'";
     $query .= " OR `dispingreds` LIKE '% " . $this->id . "')";
     if (!$show_deleted) {
         $query .= " AND dishes.deleted='0'";
     }
     $query .= " ORDER BY dishes.table_name ASC";
     $res = common_query($query, __FILE__, __LINE__);
     if (!$res) {
         return ERR_MYSQL;
     }
     while ($arr = mysql_fetch_array($res)) {
         $dish = new dish($arr['id']);
         $ingreds = $dish->dispingredients($arr['dispingreds']);
         if (!empty($ingreds) && is_array($ingreds)) {
             if (in_array($this->id, $ingreds)) {
                 $tmp = '';
                 if ($link) {
                     $tmp .= '<a href="' . $this->file . '?class=dish&command=edit&data[id]=' . $dish->id . '">';
                 }
                 $tmp .= $dish->name($_SESSION['language']);
                 if ($link) {
                     $tmp .= '</a>';
                 }
                 $output['available'][$dish->id] = $tmp;
             }
         }
     }
     return $output;
 }
function show_receipt($id)
{
    if (!$id) {
        return 1;
    }
    $table = 'account_mgmt_main';
    $query = "SELECT * FROM {$table} WHERE `id`='{$id}'";
    $res = mysql_db_query($_SESSION['common_db'], $query);
    $row = mysql_fetch_array($res);
    if ($row['annulled']) {
        switch ($row['type']) {
            case 4:
                echo ucphr('RECEIPT_ANNULLED_OK') . ".<br>\n";
                break;
            case 3:
                echo ucphr('INVOICE_ANNULLED_OK') . ".<br>\n";
                break;
            case 5:
                echo ucphr('BILL_ANNULLED_OK') . ".<br>\n";
                break;
        }
        echo GLOBALMSG_RECORD_DELETE_OK_FROM_LOG_MANY_2 . ".<br><br>";
        echo "<form name=\"form1\" action=\"receipt.php\" method=\"post\">\n";
        echo "<input type=\"hidden\" name=\"command\" value=\"delete\">\n";
        echo "<input type=\"hidden\" name=\"delete[" . $id . "]\" value=\"1\">\n";
        echo "<input type=\"submit\" value=\"" . GLOBALMSG_RECORD_DELETE . "\">";
        echo "</form>\n";
        return 0;
    }
    $table = 'account_log';
    $query = "SELECT * FROM {$table} WHERE `payment`='{$id}'";
    $res = mysql_db_query($_SESSION['common_db'], $query);
    if (!mysql_num_rows($res)) {
        return 2;
    }
    echo "<table bgcolor=\"" . color(-1) . "\">\n";
    echo "<thead ><tr>\n\t<td>" . ucfirst(phr('QUANTITY')) . "</a></td>\n\t<td>" . ucfirst(phr('DESCRIPTION')) . "</td>\n\t<td>" . ucfirst(phr('AMOUNT')) . "</td>\n\t</tr></thead>\n\t<tbody>\n";
    $i = 0;
    while ($row = mysql_fetch_array($res)) {
        if ($row['operation'] == 1) {
            $ingred = new ingredient($row['ingredient']);
            $description = "    " . ucphr('PLUS') . " " . $ingred->name($_SESSION['language']);
            unset($ingred);
        } elseif ($row['operation'] == -1) {
            $ingred = new ingredient($row['ingredient']);
            $description = "    " . ucphr('MINUS') . " " . $ingred->name($_SESSION['language']);
            unset($ingred);
        } else {
            $dish = new dish($row['dish']);
            $description = $dish->name($_SESSION['language']);
            unset($dish);
        }
        $total += $row['price'];
        $color = color($i);
        echo '<tr bgcolor="', $color, '">
		<td>', $row['quantity'], '</td>
		<td>', $description, '</td>
		<td align="right">', $row['price'], '</td>
		</tr>
		';
        $i++;
    }
    echo '<tr bgcolor="', color(-1), '">
	<td></td>
	<td>' . ucfirst(phr('TOTAL')) . '</td>
	<td align="right">', sprintf("%0.2f", $total), '</td>
	</tr>
	';
    echo "</tbody></table>";
    echo "<form name=\"form1\" action=\"receipt.php\" method=\"post\">\n";
    echo "<input type=\"hidden\" name=\"command\" value=\"delete\">\n";
    echo "<input type=\"hidden\" name=\"delete[" . $id . "]\" value=\"1\">\n";
    echo "<input type=\"submit\" value=\"" . GLOBALMSG_RECORD_DELETE . "\">";
    echo "</form>\n";
    echo "<form name=\"form1\" action=\"receipt.php\" method=\"post\">\n";
    echo "<input type=\"hidden\" name=\"command\" value=\"annul\">\n";
    echo "<input type=\"hidden\" name=\"annul[" . $id . "]\" value=\"1\">\n";
    echo "<input type=\"submit\" value=\"" . ucphr('ANNULL') . "\">";
    echo "</form>\n";
}
function dishes_list_search($data)
{
    $output = '';
    $search = strtolower(trim($data['search']));
    if (empty($search)) {
        return '';
    }
    $query = "SELECT dishes.*\n\tFROM `dishes`\n\tWHERE (LCASE(`name`) LIKE '" . $search . "%'\n\t\tOR LCASE(`name`) LIKE '% " . $search . "%'\n\t\t)";
    if (!get_conf(__FILE__, __LINE__, "invisible_show")) {
        $query .= "AND `visible`='1'";
    }
    $query .= "\n\tAND dishes.deleted='0'\n\tORDER BY name ASC";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return '';
    }
    $output .= '<table bgcolor="' . COLOR_TABLE_GENERAL . '">
	<tr>
	<th scope=col>' . ucfirst(phr('ID')) . '</th>
	<th scope=col>' . ucfirst(phr('NAME')) . '</th>
	<th scope=col>' . country_conf_currency(true) . '</th>
	</tr>
	';
    // ascii letter A
    $i = 65;
    unset($GLOBALS['key_binds_letters']);
    while ($arr = mysql_fetch_array($res)) {
        $class = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], "categories", "htmlcolor", $arr['category']);
        $dishcat = $arr['category'];
        $dishid = $arr['id'];
        $dishobj = new dish($arr['id']);
        $dishname = $dishobj->name($_SESSION['language']);
        if ($dishname == null || strlen(trim($dishname)) == 0) {
            $dishname = $arr['name'];
        }
        $dishprice = $arr['price'];
        if ($dishcat > 0) {
            // letters array follows
            if ($i < 91) {
                $GLOBALS['key_binds_letters'][$i] = $dishid;
                $local_letter = chr($i);
                $i++;
            } else {
                $local_letter = '';
            }
            $output .= '<tr>
			<td bgcolor="' . $class . '">' . $local_letter . '</td>';
            $output .= '<td bgcolor="' . $class . '" onclick="order_select(' . $dishid . ',\'order_form\'); return false;"><a href="#" onclick="JavaScript:order_select(' . $dishid . ',\'order_form\'); return false;">' . $dishname . '</a></td>';
            $output .= '<td bgcolor="' . $class . '">' . $dishprice . '</td>
			</tr>';
        }
    }
    $output .= '
	</table>';
    return $output;
}
function print_category($category)
{
    /*
    name:
    print_category($category)
    returns:
    0 - no error
    1 - no orders in this category printed
    2 - category already printed
    3 - template parsing error
    other - mysql error number
    */
    $sourceid = $_SESSION['sourceid'];
    // decided to give back the possibility to print again even if already printed
    if (!printing_orders_printed_category($category)) {
        return ERR_NO_ORDERS_PRINTED_CATEGORY;
    }
    $query = "SELECT * FROM `sources` WHERE id='{$sourceid}'";
    $res2 = common_query($query, __FILE__, __LINE__);
    if (!$res2) {
        return ERR_MYSQL;
    }
    $row2 = mysql_fetch_array($res2);
    if ($row2 != FALSE) {
        $otablenum = $row2['name'];
        $ouserid = $row2['userid'];
        $query = "SELECT * FROM `users` WHERE id='{$ouserid}'";
        $res3 = common_query($query, __FILE__, __LINE__);
        if (!$res3) {
            return mysql_errno();
        }
        $row3 = mysql_fetch_array($res3);
        $ousername = $row3['name'];
    }
    switch ($category) {
        case 1:
            $category_name = "1";
            break;
        case 2:
            $category_name = "2";
            break;
        case 3:
            $category_name = "3";
            break;
    }
    $query = "SELECT * FROM `dests` WHERE `deleted`='0'";
    $res_dest = common_query($query, __FILE__, __LINE__);
    if (!$res_dest) {
        return ERR_MYSQL;
    }
    while ($arr_dest = mysql_fetch_array($res_dest)) {
        $destid = $arr_dest['id'];
        $lang = $arr_dest['language'];
        $query = "SELECT orders.extra_care, orders.quantity, orders.dishid FROM orders";
        $query .= " JOIN dishes WHERE dishes.id=orders.dishid";
        $query .= " AND orders.sourceid ='" . $_SESSION['sourceid'] . "'";
        $query .= " AND orders.priority ={$category}";
        $query .= " AND orders.deleted = 0";
        $query .= " AND orders.printed IS NOT NULL";
        $query .= " AND orders.dishid != " . MOD_ID;
        $query .= " AND orders.dishid != " . SERVICE_ID;
        $query .= " AND orders.suspend = 0";
        $query .= " AND dishes.destid ='{$destid}'";
        $query .= " ORDER BY orders.associated_id";
        $res_ord = common_query($query, __FILE__, __LINE__);
        if (!$res_ord) {
            return ERR_MYSQL;
        }
        $tpl_print = new template();
        $msg = "";
        $output['table'] = ucfirst(lang_get($lang, 'PRINTS_TABLE')) . ": " . $_SESSION['tablenum'];
        $tpl_print->assign("table", $output['table']);
        $user = new user($_SESSION['userid']);
        $tpl_print->assign("waiter", $user->data['name']);
        $output['priority_go'] = ucfirst(lang_get($dest_language, 'PRINTS_GO_WITH')) . " ";
        $output['priority_go'] .= '{highlight}';
        $output['priority_go'] .= $category_name;
        $output['priority_go'] .= '{/highlight}';
        $tpl_print->assign("go_priority", $output['priority_go']);
        $tpl_print->assign("date", printer_print_date());
        $dest_language = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'dests', "language", $destid);
        while ($arr = mysql_fetch_array($res_ord)) {
            $dishobj = new dish($arr['dishid']);
            $dishname = $dishobj->name($dest_language);
            if ($arr['extra_care']) {
                $extra_care = " - " . '{highlight}' . ucfirst(phr('EXTRA_CARE')) . '{/highlight}';
            } else {
                $extra_care = "";
            }
            $output['orders'] .= $arr['quantity'] . ' ' . $dishname . ' ' . $extra_care . "\n";
        }
        // strips the last newline that has been put
        $output['orders'] = substr($output['orders'], 0, strlen($output['orders']) - 1);
        $tpl_print->assign("orders", $output['orders']);
        $tpl_print->assign("page_cut", printer_print_cut());
        if ($err = $tpl_print->set_print_template_file($destid, 'priority_go')) {
            return $err;
        }
        if ($err = $tpl_print->parse()) {
            $msg = "Error in " . __FUNCTION__ . " - ";
            $msg .= 'error: ' . $err . "\n";
            error_msg(__FILE__, __LINE__, $msg);
            echo nl2br($msg) . "\n";
            return 3;
        }
        $tpl_print->restore_curly();
        $msg = $tpl_print->getOutput();
        $tpl_print->reset_vars();
        $output['orders'] = '';
        $msg = str_replace("'", "", $msg);
        if (mysql_num_rows($res_ord)) {
            if ($err = print_line($destid, $msg)) {
                return $err;
            }
        }
    }
    $catprintedtext = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'sources', "catprinted", $sourceid);
    $catprintedtext .= " " . $category;
    $query = "UPDATE `sources` SET `catprinted`='{$catprintedtext}' WHERE `id` = '{$sourceid}'";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return ERR_MYSQL;
    }
    return 0;
}
function bill_save_session($sourceid)
{
    /*
    Takes every single dish and saves the following info in the waiter session
    saved data:
    price 	(in case of mod adds the price to the associated dish
    		and sets 0 to the actual dish)
    name
    special (1 if mod, 0 if not mod)
    quantity
    max_quantity (the max available to pay quantity)
    extra_care
    topay 	(the quantity that the customers asks to pay
    		it is set to max_quantity if the customer pays the full bill)
    */
    $query = "SELECT * FROM `orders` WHERE `sourceid`='{$sourceid}' AND `deleted`=0 AND `printed` IS NOT NULL ORDER BY `associated_id` ASC";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return ERR_MYSQL;
    }
    if (!mysql_num_rows($res)) {
        return ERR_NO_ORDER_FOUND;
    }
    while ($arr = mysql_fetch_array($res)) {
        $id = $arr['id'];
        $associated_id = $arr['associated_id'];
        debug_msg(__FILE__, __LINE__, "separated order select - associated id (associated_id): " . $arr['associated_id']);
        if (!isset($_SESSION['separated'][$id]['topay'])) {
            $_SESSION['separated'][$id]['topay'] = 0;
        }
        $_SESSION['separated'][$id]['quantity'] = $arr['quantity'];
        if (order_is_mod($id) == 2) {
            $_SESSION['separated'][$associated_id]['price'] += $arr['price'];
            $_SESSION['separated'][$id]['price'] = 0;
            $ingredobj = new ingredient($arr['ingredid']);
            $modname = $ingredobj->name($_SESSION['language']);
            $_SESSION['separated'][$id]['name'] = "&nbsp;&nbsp;&nbsp;" . ucfirst($modname);
            $_SESSION['separated'][$id]['special'] = true;
            debug_msg(__FILE__, __LINE__, "separated order select - found mod: " . $_SESSION['separated'][$id]['name']);
            debug_msg(__FILE__, __LINE__, "separated order select -    added price: " . $arr['price']);
        } else {
            $_SESSION['separated'][$id]['max_quantity'] = $arr['quantity'] - $arr['paid'];
            $_SESSION['separated'][$id]['price'] += $arr['price'];
            $_SESSION['separated'][$id]['dishid'] = $arr['dishid'];
            $dishobj = new dish($arr['dishid']);
            $_SESSION['separated'][$id]['name'] = ucfirst($dishobj->name($_SESSION['language']));
            $_SESSION['separated'][$id]['extra_care'] = $arr['extra_care'];
            $_SESSION['separated'][$id]['special'] = false;
            if ($_SESSION['select_all']) {
                $_SESSION['separated'][$id]['topay'] = $_SESSION['separated'][$id]['max_quantity'];
            }
        }
        if (order_is_mod($id) == 1) {
            $_SESSION['separated'][$id]['name'] = ucfirst(phr('SERVICE_FEE'));
        }
    }
    return 0;
}
 function list_rows($arr, $row)
 {
     global $tpl;
     global $display;
     $col = 0;
     if (!$this->disable_mass_delete) {
         $display->rows[$row][$col] = '<input type="checkbox" name="delete[]" value="' . $arr['id'] . '">';
         $display->width[$row][$col] = '1%';
         $col++;
     } elseif ($arr['table_id'] == TABLE_DISHES) {
         $dish = new dish($arr['id']);
         if (count($dish->ingredients()) || count($dish->dispingredients())) {
             $display->rows[$row][$col] = '<input type="checkbox" name="edit[]" value="' . $arr['id'] . '">';
         } else {
             $display->rows[$row][$col] = '&nbsp;';
         }
         $display->width[$row][$col] = '1%';
         $col++;
     } else {
         $display->rows[$row][$col] = '&nbsp;';
         $display->width[$row][$col] = '1%';
         $col++;
     }
     foreach ($arr as $field => $value) {
         if (isset($this->hide) && in_array($field, $this->hide)) {
             continue;
         }
         switch ($arr['table_id']) {
             case TABLE_INGREDIENTS:
                 $obj = new ingredient();
                 break;
             case TABLE_DISHES:
                 $obj = new dish();
                 break;
             case TABLE_CATEGORIES:
                 $obj = new category();
                 break;
             case TABLE_TABLES:
                 $obj = new table();
                 break;
             case TABLE_USERS:
                 $obj = new user();
                 break;
             case TABLE_VAT_RATES:
                 $obj = new vat_rate();
                 break;
             case TABLE_PRINTERS:
                 $obj = new printer();
                 break;
             case TABLE_STOCK_OBJECTS:
                 $obj = new stock_object();
                 break;
             case TABLE_STOCK_DISHES:
                 $obj = new dish();
                 break;
         }
         if (method_exists($obj, 'form')) {
             $link = $obj->file . '?class=' . get_class($obj) . '&amp;command=edit&amp;data[id]=' . $arr['id'];
         } else {
             $link = '';
         }
         $display->rows[$row][$col] = $value;
         if ($link && $field == 'name') {
             $display->links[$row][$col] = $link;
         }
         if ($link) {
             $display->clicks[$row][$col] = 'redir(\'' . $link . '\');';
         }
         $col++;
     }
 }
 function table_row_name($arr)
 {
     $dish = new dish($arr['dishid']);
     $dishname = $dish->name($_SESSION['language']);
     $deleted = $arr['deleted'];
     $orderid = $arr['id'];
     if ($arr['dishid'] == MOD_ID) {
         $modingred = $arr['ingredid'];
         $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'));
         }
         $dishname .= " " . $moddeddishname;
         // and finally consider any optional info (lot/few)
         if ($arr['ingred_qty'] == 1) {
             $dishname .= " " . ucfirst(phr('LOT'));
         } elseif ($arr['ingred_qty'] == -1) {
             $dishname .= " " . ucfirst(phr('FEW'));
         }
         // 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'));
     }
     return $dishname;
 }
Exemple #10
0
         $list['priority'] = $start_data['priority'];
         $list['search'] = $dishid;
         dish_list($list);
         break;
     } elseif ($num == 0) {
         // found none
         $tmp = '<b><font color="Red">' . ucfirst(phr('ERROR_NONE_FOUND')) . "</font></b><br>\n";
         $tpl->append('messages', $tmp);
         orders_list();
         break;
     } else {
         // found one, we directly assume that's the dish the user wanted
         $dishid = $num;
     }
 }
 $dish = new dish($dishid);
 if (!$dish->exists()) {
     $tmp = '<b><font color="Red">' . ucfirst(phr('DISH_DOES_NOT_EXIST')) . "</font></b><br>\n";
     $tpl->append('messages', $tmp);
     orders_list();
     break;
 }
 if ($dishid) {
     $id = orders_create($dishid, $start_data);
 }
 if ($id) {
     $err = 0;
 } else {
     $err = ERR_UNKNOWN;
 }
 status_report('CREATION', $err);
function toplist_show()
{
    global $tpl;
    $_SESSION['order_added'] = 0;
    $query = "SELECT * FROM `last_orders`";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return ERR_MYSQL;
    }
    if (!mysql_num_rows($res)) {
        return 1;
    }
    while ($arr = mysql_fetch_array($res)) {
        $dishid = $arr['dishid'];
        if ($dishid == MOD_ID || $dishid == SERVICE_ID) {
            continue;
        }
        if (!isset($toplist[$dishid])) {
            $toplist[$dishid] = 0;
        }
        $toplist[$dishid]++;
    }
    if (!is_array($toplist)) {
        return 0;
    }
    arsort($toplist);
    reset($toplist);
    $chk[1] = "";
    $chk[2] = "";
    $chk[3] = "";
    $tmp = '
	<form action="orders.php" method="POST" name="toplist_form">
	<INPUT TYPE="HIDDEN" NAME="command" VALUE="create">
	<INPUT TYPE="HIDDEN" NAME="dishid" VALUE="0">';
    if (CONF_TOPLIST_HIDE_QUANTITY) {
        $tmp .= '
		<INPUT TYPE="HIDDEN" NAME="data[quantity]" VALUE="1">';
    }
    if (CONF_TOPLIST_HIDE_PRIORITY) {
        $tmp .= '
		' . ucfirst(phr('PRIORITY')) . ':
		<input type="radio" ' . $chk[1] . ' name="data[priority]" value=1>1
		<input type="radio" ' . $chk[2] . ' name="data[priority]" value=2>2
		<input type="radio" ' . $chk[3] . ' name="data[priority]" value=3>3';
    }
    $tmp .= '
	<table bgcolor="' . COLOR_TABLE_GENERAL . '">
	<tbody>
		<tr align="center">
			<td colspan="4">
				<b>' . ucfirst(phr('TOPLIST')) . '(' . ucfirst(phr('LASTS')) . ' ' . CONF_TOPLIST_SAVED_NUMBER . ')</b>
				&nbsp;&nbsp;
				<a href="orders.php?command=set_show_toplist">
				<img src="' . ROOTDIR . '/images/waiter/fileclose.png" border="0" alt="' . ucphr('HIDE_TOPLIST') . '">
				</a>
			</td>
		</tr>
';
    $i = 0;
    while ($i < get_conf(__FILE__, __LINE__, "top_list_show_top")) {
        if (list($key, $value) = each($toplist)) {
            $category = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'dishes', 'category', $key);
            $bgcolor = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'categories', 'htmlcolor', $category);
            $tmp .= '
		<tr bgcolor="' . $bgcolor . '">';
            if (table_is_takeaway($_SESSION['sourceid'])) {
                $tmp .= '
			<input type="hidden" name="data[priority]" value=1>';
            } elseif (!$i && !CONF_TOPLIST_HIDE_PRIORITY) {
                $tmp .= '
			<td rowspan="' . (get_conf(__FILE__, __LINE__, "top_list_show_top") + 1) . '" bgcolor="' . COLOR_TABLE_GENERAL . '">
			1<input type="radio" ' . $chk[1] . ' name="data[priority]" value=1><br />
			2<input type="radio" ' . $chk[2] . ' name="data[priority]" value=2><br />
			3<input type="radio" ' . $chk[3] . ' name="data[priority]" value=3><br />
			</td>';
            }
            if (!$i && !CONF_TOPLIST_HIDE_QUANTITY) {
                $qtydata['nolabel'] = 1;
                $tmp .= '
			<td rowspan="' . (get_conf(__FILE__, __LINE__, "top_list_show_top") + 1) . '" bgcolor="' . COLOR_TABLE_GENERAL . '">
			' . quantity_list($qtydata) . '
			</td>';
            }
            $dishobj = new dish($key);
            $dishname = $dishobj->name($_SESSION['language']);
            $tmp .= '
			<td>
				' . $value . '
			</td>';
            $tmp .= '
			<td valign="middle" onclick="order_select(\'' . $key . '\',\'toplist_form\');">
			<a href="#" onclick="JavaScript:order_select(\'' . $key . '\',\'toplist_form\'); return false;">
			' . $dishname . '
			</a>
			</td>';
            $tmp .= '
		</tr>';
        }
        $i++;
    }
    $tmp .= '
	</table>
	</form>';
    $tpl->assign('toplist', $tmp);
    return 0;
}