function ticketslist_to_sorted_grouped($sortBy, $sortOrder, $ticket_list, $startFrom, $eventName, $eventDate, $venueName, $productionID, $city, $eventID)
{
    include '../include/host_info.inc.php';
    global $query_string;
    global $eventTypeID;
    # Section Row Price Seat Quanity Button
    $SECTION_WIDTH = "29%";
    $ROW_WIDTH = "15%";
    $PRICE_WIDTH = "15%";
    $SEAT_WIDTH = "13%";
    $QUANTITY_WIDTH = "12%";
    $BUYNOW_WIDTH = "16%";
    $MAX_TIX_PP = 500;
    $NUM_TIX_PP = $MAX_TIX_PP;
    echo '<div class="tickets">';
    $num_pages = ceil((double) count($ticket_list) / (double) $MAX_TIX_PP);
    #echo count($ticket_list) . " tickets sets available for this Event<br/>";
    if ($num_pages > 1) {
        print_page_nav($startFrom, $num_pages, $sortBy, $sortOrder, $productionID);
    }
    $image_path = "{$root_url}/Images/";
    $image_up = "arrow-up.gif";
    $image_down = "arrow-down.gif";
    $image_none = "arrow-none.gif";
    $ticket_limit_reached = 0;
    if ($sortBy == 'sec' || $sortBy == 'row') {
        foreach ($ticket_list as $key => $row) {
            $SeatSection[$key] = $row['SeatSection'];
            $TicketPrice[$key] = $row['TicketPrice'];
            $SeatRow[$key] = $row['SeatRow'];
        }
        if ($sortOrder == 'desc') {
            $sortOrderCode = SORT_DESC;
        } else {
            $sortOrderCode = SORT_ASC;
        }
        if ($sortBy == 'sec') {
            array_multisort($SeatSection, $sortOrderCode, $TicketPrice, SORT_ASC, $ticket_list);
        } else {
            array_multisort($SeatRow, $sortOrderCode, $TicketPrice, SORT_ASC, $ticket_list);
        }
        $sorted_array = $ticket_list;
    } elseif ($sortBy == 'pr') {
        if ($sortOrder == 'desc') {
            $sorted_array = array_reverse($ticket_list);
        } else {
            $sorted_array = $ticket_list;
        }
    } else {
        $sorted_array = $ticket_list;
    }
    echo "\n";
    echo '<table  width="100%" cellspacing="0">';
    $url = make_production_url($eventName, $productionID, $city, $eventTypeID);
    $url_array = explode('?', $url);
    $url = $url_array[0];
    $query_string = "&amp;event_id={$productionID}";
    echo "\n<tr class=\"tableHeading\">";
    $sortable_columns = array("sec" => "Section", "row" => "Row", "pr" => "Price");
    foreach ($sortable_columns as $columnID => $columnHeading) {
        if (strlen($sortBy) == 0 && $columnID == 'pr') {
            $nextSortOrder = 'desc';
            $arrow = $image_path . $image_up;
        } elseif ($sortBy == $columnID) {
            if ($sortOrder == 'desc') {
                $nextSortOrder = 'asc';
                $arrow = $image_path . $image_down;
            } else {
                $nextSortOrder = 'desc';
                $arrow = $image_path . $image_up;
            }
        } else {
            $nextSortOrder = 'asc';
            $arrow = $image_path . $image_none;
        }
        echo "\n";
        if ($columnID == 'sec') {
            echo '<th width="' . $SECTION_WIDTH . '">';
        } elseif ($columnID == 'pr') {
            echo '<th width="' . $PRICE_WIDTH . '">';
        } else {
            echo '<th width="' . $ROW_WIDTH . '">';
        }
        $url_sort_params = $url . "?sortBy={$columnID}&amp;sortOrder={$nextSortOrder}" . $query_string;
        echo '<a href="' . $url_sort_params . "\">{$columnHeading}</a><img src=\"{$arrow}\" alt=\"&darr;\"/></th>";
    }
    echo "\n";
    echo '<th width="' . $SEAT_WIDTH . '">Seat No.</th><th width="' . $QUANTITY_WIDTH . '">Quantity</th><th width="' . $BUYNOW_WIDTH . '">&nbsp;&nbsp;</th>';
    echo "\n</tr>";
    echo "\n</table>";
    $ticket_index = 1;
    for ($j = ($startFrom - 1) * $MAX_TIX_PP; $j < $startFrom * $MAX_TIX_PP - 1 && $j < count($sorted_array); $j++) {
        # foreach($sorted_array as $index=>$ticket_info) {
        # echo '<form action="/ticket_order.html" method="post">';
        echo '<table width="100%" cellspacing="0">';
        if ($ticket_index % 2 == 0) {
            $class = "class=\"even\"";
        } else {
            $class = "class=\"odd\"";
        }
        echo "\n<tr {$class}>";
        echo '<td width="' . $SECTION_WIDTH . '"><strong>Section: </strong>' . $sorted_array[$j]['SeatSection'] . "\n" . '</td><td width="' . $ROW_WIDTH . '"><strong>Row: </strong>' . $sorted_array[$j]['SeatRow'] . '</td><td width="' . $PRICE_WIDTH . '">' . $sorted_array[$j]['TicketPrice'] . '</td><td width="' . $SEAT_WIDTH . '">' . $sorted_array[$j]['SeatFrom'] . "-" . $sorted_array[$j]['SeatThru'] . '</td>';
        echo '<td width="' . $QUANTITY_WIDTH . '">';
        echo '<select id="Ticks' . $ticket_index . '">';
        $split_ary = explode(' ', $sorted_array[$j]['ValidSplits']);
        echo $sorted_array[$j]['ValidSplits'] . "<br/>";
        for ($i = 0; $i < count($split_ary); $i++) {
            echo '<option>' . $split_ary[$i] . '</option>';
        }
        echo '</select>';
        echo '</td>';
        $section_lower = strtolower($sorted_array[$j]['SeatSection']);
        $seat_lower = strtolower($sorted_array[$j]['SeatRow']);
        $ticketid = $sorted_array[$j]['TicketID'];
        # echo "\n<span class=\"tiny\">Up to " . $sorted_array[$j]['Available'] . " Available</span>";
        #	echo "</td>";
        #########
        # OLD, non-framed
        # https://tickettransaction2.com/Checkout.aspx?brokerid=982&sitenumber=6&tgid=455676449&treq=8&evtID=545276&price=187.00&SessionId=JFv2u
        $tprice = substr($sorted_array[$j]['TicketPrice'], 1);
        $session_id = GenerateSessionId();
        $req_quantity = 1;
        echo '<td width="' . $BUYNOW_WIDTH . '">';
        echo '<a target="_self" href="javascript:SubmitPurchaseLink(' . "'Ticks{$ticket_index}', '" . $sorted_array[$j]['TicketID'] . "', '{$tprice}', '{$productionID}')" . '">';
        echo '<img src="' . $root_url . '/Images/tickets_br.gif" alt="Buy ' . $eventName . " " . $venueName . " Section " . $sorted_array[$j]['SeatSection'] . " Row " . $sorted_array[$j]['SeatRow'] . ' tickets"/></a>';
        echo "\n";
        echo "\n</tr>";
        echo "\n<tr {$class}>\n<td style=\"text-align=left;\" colspan=\"6\"><span class=\"tiny\">" . utf8_decode($sorted_array[$j]['Descr']) . "</span></td></tr>";
        echo "\n</table>";
        $ticket_index++;
    }
    if ($num_pages > 1) {
        print_page_nav($startFrom, $num_pages, $sortBy, $sortOrder, $productionID);
    }
    echo "</div>";
}
function ticketslist_to_sorted_grouped($sortBy, $sortOrder, $ticket_list, $startFrom, $eventName, $eventDate, $venueName, $productionID, $city)
{
    include '../include/host_info.inc.php';
    global $query_string;
    global $eventTypeID;
    # Section Row Price Seat Quanity Button
    $SECTION_WIDTH = "29%";
    $ROW_WIDTH = "15%";
    $PRICE_WIDTH = "15%";
    $SEAT_WIDTH = "13%";
    $QUANTITY_WIDTH = "12%";
    $BUYNOW_WIDTH = "16%";
    $MAX_TIX_PP = 500;
    $NUM_TIX_PP = $MAX_TIX_PP;
    echo '<div class="tickets">';
    $num_pages = ceil((double) count($ticket_list) / (double) $MAX_TIX_PP);
    #echo count($ticket_list) . " tickets sets available for this Event<br/>";
    if ($num_pages > 1) {
        print_page_nav($startFrom, $num_pages, $sortBy, $sortOrder, $productionID);
    }
    $image_path = "{$root_url}/Images/";
    $image_up = "arrow-up.gif";
    $image_down = "arrow-down.gif";
    $image_none = "arrow-none.gif";
    $ticket_limit_reached = 0;
    if ($sortBy == 'sec' || $sortBy == 'row') {
        foreach ($ticket_list as $key => $row) {
            $SeatSection[$key] = $row['SeatSection'];
            $TicketPrice[$key] = $row['TicketPrice'];
            $SeatRow[$key] = $row['SeatRow'];
        }
        if ($sortOrder == 'desc') {
            $sortOrderCode = SORT_DESC;
        } else {
            $sortOrderCode = SORT_ASC;
        }
        if ($sortBy == 'sec') {
            array_multisort($SeatSection, $sortOrderCode, $TicketPrice, SORT_ASC, $ticket_list);
        } else {
            array_multisort($SeatRow, $sortOrderCode, $TicketPrice, SORT_ASC, $ticket_list);
        }
        $sorted_array = $ticket_list;
    } elseif ($sortBy == 'pr') {
        if ($sortOrder == 'desc') {
            $sorted_array = $ticket_list;
        } else {
            $sorted_array = array_reverse($ticket_list);
        }
    } else {
        $sorted_array = array_reverse($ticket_list);
    }
    echo '<table  width="100%" cellspacing="0">';
    $url = make_production_url($eventName, $productionID, $city, $eventTypeID);
    $url_array = explode('?', $url);
    $url = $url_array[0];
    $query_string = "&event_id={$productionID}";
    echo "<tr class=\"tableHeading\">";
    $sortable_columns = array("sec" => "Section", "row" => "Row", "pr" => "Price");
    foreach ($sortable_columns as $columnID => $columnHeading) {
        if (strlen($sortBy) == 0 && $columnID == 'pr') {
            $nextSortOrder = 'desc';
            $arrow = $image_path . $image_up;
        } elseif ($sortBy == $columnID) {
            if ($sortOrder == 'desc') {
                $nextSortOrder = 'asc';
                $arrow = $image_path . $image_down;
            } else {
                $nextSortOrder = 'desc';
                $arrow = $image_path . $image_up;
            }
        } else {
            $nextSortOrder = 'asc';
            $arrow = $image_path . $image_none;
        }
        if ($columnID == 'sec') {
            echo '<th width="' . $SECTION_WIDTH . '">';
        } elseif ($columnID == 'pr') {
            echo '<th width="' . $PRICE_WIDTH . '">';
        } else {
            echo '<th width="' . $ROW_WIDTH . '">';
        }
        $url_sort_params = $url . "?sortBy={$columnID}&sortOrder={$nextSortOrder}" . $query_string;
        echo '<a href="' . $url_sort_params . "\">{$columnHeading}</a><img src=\"{$arrow}\" alt=\"&darr;\"/></th>";
    }
    echo '<th width="' . $SEAT_WIDTH . '">Seat No.</th><th width="' . $QUANTITY_WIDTH . '">Quantity</th><th width="' . $BUYNOW_WIDTH . '">&nbsp;&nbsp;</th>';
    echo "</tr>";
    echo "</table>";
    $ticket_index = 1;
    for ($j = ($startFrom - 1) * $MAX_TIX_PP; $j < $startFrom * $MAX_TIX_PP - 1 && $j < count($sorted_array); $j++) {
        # foreach($sorted_array as $index=>$ticket_info) {
        # echo '<form action="/ticket_order.html" method="post">';
        echo '<table width="100%" cellspacing="0">';
        if ($ticket_index % 2 == 0) {
            $class = "class=\"even\"";
        } else {
            $class = "class=\"odd\"";
        }
        echo "\n<tr {$class}>";
        echo '<td width="' . $SECTION_WIDTH . '"><strong>Section: </strong>' . $sorted_array[$j]['SeatSection'] . "\n" . '</td><td width="' . $ROW_WIDTH . '"><strong>Row: </strong>' . $sorted_array[$j]['SeatRow'] . '</td><td width="' . $PRICE_WIDTH . '">' . $sorted_array[$j]['TicketPrice'] . '</td><td width="' . $SEAT_WIDTH . '">' . $sorted_array[$j]['SeatFrom'] . "-" . $sorted_array[$j]['SeatThru'] . '</td><td width="' . $QUANTITY_WIDTH . '"> ';
        $section_lower = strtolower($sorted_array[$j]['SeatSection']);
        $seat_lower = strtolower($sorted_array[$j]['SeatRow']);
        if (preg_match("/^lawn\$/", $section_lower) || preg_match("/^ga\$/", $section_lower) || preg_match("/^g\\.a\$/", $section_lower) || preg_match("/^ga\$/", $seat_lower) || preg_match("/^g\\.a\\.\$/", $section_lower) || preg_match("/^ga\\.\$/", $seat_lower)) {
            $min_num_tickets = 1;
        } else {
            if ($sorted_array[$j]['Available'] % 2 == 0) {
                $min_num_tickets = 2;
            } else {
                $min_num_tickets = 1;
                $max_num_tickets = $sorted_array[$j]['Available'];
                $num_tickets_array = array();
                for ($num_tickets = $min_num_tickets; $num_tickets <= $max_num_tickets; $num_tickets++) {
                    if ($max_num_tickets - $num_tickets != 1) {
                        $num_tickets_array[] = $num_tickets;
                    }
                }
                $num_tickets_descending_array = array_reverse($num_tickets_array);
            }
        }
        $ticketid = $sorted_array[$j]['TicketID'];
        echo "\n<span class=\"tiny\">Up to " . $sorted_array[$j]['Available'] . " Available</span>";
        echo "</td>";
        #########
        # OLD, non-framed
        echo '<td width="' . $BUYNOW_WIDTH . '"><a href="https://www.ticketsnow.com/buytickets.aspx?id=' . $ticketid . '&reqqty=0&client=4089" rel="nofollow"><img src="/Images/buy_tix.png" onmouseover="this.src=\'/Images/buy_tix_mouse_over.png\';" onmouseout="this.src=\'/Images/buy_tix.png\';" alt="' . "Buy {$eventName} {$venueName} Section " . $sorted_array[$j]['SeatSection'] . " Row " . $sorted_array[$j]['SeatRow'] . ' tickets"/></a>';
        # echo ' <input type="image" src="/Images/buy_tix.png" onmouseover="this.src=\'/Images/buy_tix_mouse_over.png\';" onmouseout="this.src=\'/Images/buy_tix.png\';" value="Submit" alt="' . "Buy $eventName $venueName Section " . $sorted_array[$j]['SeatSection'] . " Row " . $sorted_array[$j]['SeatRow'] . ' tickets" /></td>';
        #########
        echo '<td width="18%">';
        # echo '<input type="hidden" name="ticket_id" value="' . $ticketid . '"/>';
        # echo '<input type="hidden" name="event_name" value="' . $eventName . '"/>';
        # echo '<input type="hidden" name="event_date" value="' . $eventDate . '"/>';
        # echo '<input type="hidden" name="venue_name" value="' . $venueName . '"/>';
        # echo '<input type="hidden" name="quantity" value="0"/>';
        # echo ' <input type="image" src="/Images/buy_tix.png" onmouseover="this.src=\'/Images/buy_tix_mouse_over.png\';" onmouseout="this.src=\'/Images/buy_tix.png\';" value="Submit" alt="' . "Buy $eventName $venueName Section " . $sorted_array[$j]['SeatSection'] . " Row " . $sorted_array[$j]['SeatRow'] . ' tickets" /></td>';
        # echo '<input type="hidden" name="quantity" value="0"/> <input type="image" src="/Images/buy_tix.png" value="Submit" alt="' . "Buy $eventName $venueName Section " . $sorted_array[$j]['SeatSection'] . " Row " . $sorted_array[$j]['SeatRow'] . ' tickets" /></td>';
        # old echo '<input type="hidden" name="quantity" value="0"/> <button title="Buy these Tickets." type="submit" name="submit" value="1">Order</button></td>';
        #echo "<td><span class=tiny>" . utf8_decode($sorted_array[$j]['Descr']) . "</span>&nbsp;</td>";
        #		# echo "</form>";
        echo "</tr>";
        echo "<tr {$class}><td style=\"text-align=left;\" colspan=\"6\"><span class=\"tiny\">" . utf8_decode($sorted_array[$j]['Descr']) . "</span></td></tr>";
        echo "</table>";
        #echo "</form>";
        $ticket_index++;
    }
    if ($num_pages > 1) {
        print_page_nav($startFrom, $num_pages, $sortBy, $sortOrder, $productionID);
    }
    echo "</div>";
}
            echo "{$action}</td>";
            echo '<td align="left" width="4%">&nbsp;' . $dates . '</td>';
            echo '<td align="left" width="30">&nbsp;' . $ID . '<input type="hidden" name="ID_' . $i . '" id="ID_' . $i . '" value="' . $ID . '"/></td>';
            $ev_url = make_event_url($name);
            $ev_url = "www.mongotickets.com" . $ev_url;
            echo '<td align="left" width="33%"><input type="text" value="' . $ev_url . '" size="60"/></td>';
            echo '</tr>';
            $i++;
        }
        echo '<tr>
                		<td colspan="9" align="center"> <input type="submit" value="Update" /> </td>
				</tr>';
        echo '</form>';
        echo '</table>';
        if ($num_pages > 1) {
            print_page_nav($start, $num_pages, $url_params);
        }
    } else {
    }
    mysql_close($dbh);
} else {
    print 'I cannot connect to the database because: ' . mysql_error();
}
ob_end_flush();
function Breadcrumbs($categoryID, $eventID)
{
    $Bsql = "SELECT C.CategoryID, C.CategoryName" . " FROM ModifiedPreorderTreeTraversalCategories AS B, ModifiedPreorderTreeTraversalCategories AS C" . " WHERE (B.lft BETWEEN C.lft AND C.rgt)" . " AND (B.CategoryID = {$categoryID})" . " ORDER BY C.lft";
    #Might want to change to (B.lft BETWEEN (C.lft+1) AND C.rgt)
    $result = mysql_query($Bsql);
    $top_level_category_array = array(2, 3, 4);
    $breadcrumb_string = "";