$Location = $_POST["SrchLocation"];
 echo "Saving..{$Location}..";
 if ($Status == 'Closed') {
     $Closed = date("Y-m-d H:i:s");
 }
 $f->save_values();
 if (!$id) {
     $db->query("SELECT LAST_INSERT_ID();");
     $db->next_record();
     $TicketNo = $db->f(0);
 } else {
     $TicketNo = $id;
 }
 if ($Comment) {
     $submit = "Add";
     $f = new SupportCommentsform();
     $ByUser = $auth->auth["uname"];
     $TimeStamp = date("Y-m-d H:i:s");
     $id = "";
     $_POST["id"] = "";
     $f->save_values();
 }
 echo "<b>Done!</b><br>\n";
 if ($Status == 'Closed') {
     echo "<META HTTP-EQUIV=REFRESH CONTENT=\"20; URL=" . $sess->url("SupportTickets.php");
     echo $sess->add_query(array("SrchLocation" => "Any", "Assigned" => "anyone"));
     echo "\">";
     echo "&nbsp<a href=\"" . $sess->url("SupportTickets.php");
     echo $sess->add_query(array("SrchLocation" => "Any", "Assigned" => "anyone"));
 } else {
     echo "<META HTTP-EQUIV=REFRESH CONTENT=\"20; URL=" . $sess->url("SupportComments.php");
function SupportEmail($TicketNo, $OldStatus = "")
{
    global $UserName, $Name, $Company, $StreetAddress, $Town, $State, $PostCode, $CO, $OtherDetail;
    global $Quantity, $ProductCode, $PartNo, $Description, $Price, $Duration, $Rate, $Details, $Email, $Comment, $ByContact;
    global $HomePhone, $WorkPhone, $Mobile, $Status, $ShortDesc, $EngineerEmail, $Created, $EnteredBy, $SequenceNo;
    global $AssignedTo, $ByUser;
    if ($TicketNo < 1) {
        return false;
    }
    $Level = 0;
    $db = new DB_hotspot();
    $stf = new SupportTicketsform();
    $stf->find_values($TicketNo);
    $mf = new userinfoform();
    $mf->find_values(UserID($UserName));
    $EngineerEmail = get_email($AssignedTo);
    if ($OldStatus) {
        $Status = $OldStatus . "->" . $Status;
    }
    $subj = "Ticket: {$TicketNo}, {$Status}, {$ShortDesc}";
    $Msg = "Job for: <b>{$UserName}, {$Name}</b><br>\n";
    if ($StreetAddress . $Town . $State . $PostCode) {
        $Msg .= "at: <b>";
        if ($StreetAddress) {
            $Msg .= "{$StreetAddress}, ";
        }
        if ($Town) {
            $Msg .= "{$Town}, ";
        }
        if ($State) {
            $Msg .= "{$State}, ";
        }
        if ($PostCode) {
            $Msg .= "{$PostCode}";
        }
        $Msg .= "</b><br>\n";
    }
    if (isset($HomePhone)) {
        $Msg .= "HomePhone: <b>{$HomePhone}</b><br>\n";
    }
    if (isset($WorkPhone)) {
        $Msg .= "WorkPhone: <b>{$WorkPhone}</b><br>\n";
    }
    if (isset($Mobile)) {
        $Msg .= "Mob: <b>{$Mobile}</b><br>\n";
    }
    if (isset($Mail)) {
        $Msg .= "Email: <b>{$Mail}</b><br>\n";
    }
    $Msg .= "------------------------------------------------------------<br>\n";
    $Msg .= "Entered By: <b>{$EnteredBy}</b><br>\n";
    $Msg .= "Date: <b>{$Created}</b><br>\n";
    if (isset($Location)) {
        $Msg .= "Location: <b>{$Location}</b><br>\n";
    }
    if (isset($RoomNo)) {
        $Msg .= "Room No: <b>{$RoomNo}</b><br>\n";
    }
    if (isset($Severity)) {
        $Msg .= "Severity: <b>{$Severity}</b><br>\n";
    }
    if ($Level > 0) {
        $Msg .= "Level: <b>{$Level}</b><br>\n";
    }
    $Msg .= "Description: <b>{$ShortDesc}</b> {$OtherDetail}<br>\n";
    $Msg .= "------------------------------------------------------------<br>\n";
    /*
    	$db->query("select id from SupportParts where TicketNo='".$TicketNo."'");
    	$sp = new SupportPartsform;
    	while ($db->next_record()) {
    		$sp->find_values($db->f(0));
    		$Msg .= "Part: <b>$Quantity x $ProductCode, $PartNo, $Description @ $Price</b><br>\n";
    	}
    	$db->query("select id from SupportDetails where TicketNo='".$TicketNo."'");
    	$sd = new SupportDetailsform;
    	while ($db->next_record()) {
    		$sd->find_values($db->f(0));
    		$Msg .= "Work: <b>$Duration minutes @ $Rate /hour, $Details</b><br>\n";
    	}
    */
    $db->query("select distinct FileName from SupportFiles where TicketNo='" . $TicketNo . "'");
    while ($db->next_record()) {
        $Msg .= "Attachment: http://os.{$CO}.com.au/files/{$TicketNo}/" . $db->f(0) . "<br>\n";
    }
    $db->query("select id from SupportComments where TicketNo='" . $TicketNo . "'");
    $sc = new SupportCommentsform();
    while ($db->next_record()) {
        $sc->find_values($db->f(0));
        $mf->find_values($ByContact);
        $Msg .= "Comment by <b>{$ByUser}:</b> ";
        $Msg .= str_replace('" src="/candy/', '" src="http://os.' . $CO . '.com.au/candy/', $Comment);
        $Msg .= "<br>\n";
    }
    $url = "https://os.{$CO}.com.au/SupportTickets.php?cmd=View&id=" . $TicketNo;
    $Msg .= "<a href='{$url}'>{$url}</a><br>\n";
    $hdrs = "From: ticket+{$TicketNo}@{$CO}.net.au";
    if ($EngineerEmail) {
        $hdrs .= "\r\nTo: {$EngineerEmail}";
    }
    htmlMail("info@{$CO}.com.au", $subj, $Msg, $hdrs);
    //, $text="", $name="", $type="Application/Octet-Stream", $data="", $name2="", $display2="")
    echo "<pre>";
    echo $hdrs;
    echo $subj;
    echo "\n";
    echo $Msg;
    echo "</pre>";
}