Click here to get back home

can't redirect to Excel

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
can't redirect to Excel JRough 07-19-2008
Posted by JRough on July 19, 2008, 12:58 am
Please log in for more thread options
I have tried this 4 2 weeks and I need some help. There are 3 other
pages referenced on this page but I'm going to start with this page
in case I missed something. It is called current_sightings.php. All
I want to do is redirect to Excel in the case of the External user.
The first if statement creates a form. The elseif redirects the
external user to only his own listings. I want the results for the
Internal user query SELECT_sightings_leasecars.() to go to my
current_sightingsXL.php page. Where/How would I put the redirect? I
think it should be after the switch for external users. The
getTableHeaders() function is the string that gets passed. All the
pages work except I can't redirect the output to Excel.

Something like this:


        if($_POST['assign']=='Open in Excel')){
        Header("Location:
current_sightingsXL.php?param=".$_Post['id']."&lease_id=".$id);}

But I don't know where to put it. I could give you the
current_sightingsXL.php page if you need it but right now it isn't
redirecting anyway and I could test it if I got it to redirect.



tia,

<?




include './includes/config.inc.php';
include $include_path.'dates.inc.php';
include $include_path."LMS_functions.inc.php";

#// ###############################################
#// Is the user logged in?
Validate_login("current_sightings.php");

if(empty($id)&&($_SESSION["LMS_USER_DESC"]=='internal')){
# THIS IS id INSTEAD OF lease_id B/C ONE DAY WE MIGHT HAVE CUSTOMER
SUB GROUPS OR MANAGED CARS
$destroyed = GetDestroyed_lease_id();
$result = SELECT_leasesCLM();
$TPL_ids = "<SELECT name='id' class=box size=8>\n";
$trbg = "";

while($row = mysqBul_fetch_assoc($result)){
$id         = $row['lease_id'];
$lnum = $row['lease_num'];
$comp = $row['comp_name'];

$trbg = GetTRBG($trbg);

$TPL_ids.=" <OPTION VALUE='".$id;
$TPL_ids.="' ".$trbg.">".$lnum." - ".$comp."</OPTION>\n";
}

$TPL_ids.="</SELECT>\n";
include "header.php";
include $template_path."current_sightings_php.html";


}elseif($_POST['redirect']&&$_POST['redirect']!=$_SERVER['PHP_SELF']){
Header("Location: ".$_POST['redirect'].".php?id=".$_POST['id']);
exit;
/*
}elseif ($_POST['assign']=='Open in Excel'){
        Header("Location: current_sightingsXL.php?param=".$_Post['id']."&id=".
$_id);
exit;*/

}else{

# DETERMINE PAGE ACCORDING TO USER TYPE
switch ($_SESSION["LMS_USER_DESC"]){
case "customer":
$id = $_SESSION["LMS_LOGGED_IN"];
$MSG_carlist = "CURRENT SIGHTINGS";
$result =
SELECT_sightings_customercars($id,CLM_order_by($order_by));
break;
case "internal":
$MSG_carlist = "CURRENT SIGHTINGS FOR ".SELECT_lease_num($id)."
".SELECT_comp_name($id);
$result =
SELECT_sightings_leasecars($id,CLM_order_by($order_by));
break;
#case "internal_ltd":
# break;
}
$TPL_carnumbers = GetTableHeaders($id);
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($row);
}

$TPL_carnumbers.="</table>";

include "header.php";
include $template_path."template_carlist.html";

}


include "footer.php";
######################################
##
##                FUNCTIONS
##
######################################

function GetTableHeaders($id){
return "<table>
                                         <th><a href='current_sightings.php?id=".
$id."&order_by=l_e'>L_E</a></th>
                                        <th><a href='current_sightings.php?id=".$id."&'>Carnumber</a></
th>
                                        <th>Type</th>
                                        <th><a href='current_sightings.php?id=".
$id."&order_by=location'>Location</a></th>
                                        <th><a href='current_sightings.php?id=".
$id."&order_by=sighting_date'>Sighting Date</a></th>
                                        <th><a href='current_sightings.php?id=".
$id."&order_by=classification'>Code</a></th>
                                        <th><a href='current_sightings.php?id=".
$id."&order_by=railroad'>RR</a></th>
                                        <th><a href='current_sightings.php?id=".
$id."&order_by=origin'>Origin</a></th>
                                        <th><a href='current_sightings.php?id=".
$id."&order_by=destination'>Destination</a></th>
                                        <th><a href='current_sightings.php?id=".$id."&order_by=eta'>ETA</
a></th>";
}

function GetCars($id,$type,$order_by){
switch($type){
case 'lease':
        return SELECT_sightings_leasecars($id,$order_by);
        break;
default:
        return SELECT_sightings_leasecars($id,$order_by);
        break;
}
}

function MakeSighting($row){
$mark = $row['car_mark'];
$num = $row['car_number'];
$l_e                                 = $row['l_e'];
$carnumber                 = MakeCarnumber($mark,$num);
$location_city         = $row['location_city'];
$location_state         = $row['location_state'];
$sighting_date         = $row['sighting_date'];
$classification         = $row['classification'];
$railroad                         = $row['railroad'];
$origin_city                 = $row['origin_city'];
$origin_state                 = $row['origin_state'];
$destination_city = $row['destination_city'];
$destination_state = $row['destination_state'];
$eta                                 = $row['eta'];
if($l_e=='L'){
        $trbg = "class='trbg'";
}else{
        $trbg = "";
}
return "<tr ".$trbg.">
                <td align='center'>".$l_e."</td>
                <td><a href='clm_history.php?mark=".$mark."&num=".$num."'>".
$carnumber."</a></td>
                <td align='center'>".GetMechanicalDesignationCarnumber($mark,
$num)."</td>
                <td>".MakeCity($location_city,$location_state)."</td>
                <td>".CLM_dateFormat($sighting_date)."</td>
                <td>".$classification."</td>
                <td>".$railroad."</td>
                <td>".MakeCity($origin_city,$origin_state)."</td>
                <td>".MakeCity($destination_city,$destination_state)."</td>
                <td>".CLM_dateFormat($eta)."</td>
         </tr>";
}

################################
##
##                 QUERIES
##
################################
function SELECT_leasesCLM(){
$query = "SELECT DISTINCT l.lease_id, m.lease_num, co.comp_name
                FROM INTERNAL_LEASES l, INTERNAL_MASTER_LEASE m, INTERNAL_COMPANY
co,
                 INTERNAL_CAR_LEASE cl, INTERNAL_REMARK r, INTERNAL_CLM c
                 WHERE co.comp_id = m.comp_id
                AND m.master_lease_id = l.master_lease_id
                AND l.lease_id = cl.lease_id
                AND cl.end_date IS NULL
                AND cl.remark_id = r.remark_id
                AND r.car_mark = c.car_mark
                AND r.car_number = c.car_number";
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
return $result;
}

function SELECT_lease_num($lease_id){
$query = "SELECT m.lease_num
                        FROM INTERNAL_MASTER_LEASE m, INTERNAL_LEASES l
                        WHERE l.lease_id =".$lease_id."
                        AND l.master_lease_id = m.master_lease_id";
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
$row = mysql_fetch_row($result);
return $row[0];
}

function SELECT_comp_name($lease_id){
$query = "SELECT comp_name
                        FROM INTERNAL_LEASES l, INTERNAL_MASTER_LEASE m, INTERNAL_COMPANY
c
                        WHERE l.lease_id = ".$lease_id."
                        AND l.master_lease_id = m.master_lease_id
                        AND m.comp_id = c.comp_id";
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
$row = mysql_fetch_row($result);
return $row[0];
}

function SELECT_sightings_customercars($id,$order_by){
$query = "SELECT c.l_e,
                                 c.car_mark, c.car_number,
                                 c.location_city, c.location_state,
                                 c.sighting_date,
                                 e.classification,
                                 c.railroad,
                                 s.city as origin_city,
                                 s.state as origin_state,
                                 c.destination_city, c.destination_state,
                                 t.eta
                        FROM INTERNAL_CUSTOMER_USERS cu, INTERNAL_MASTER_LEASE m,
INTERNAL_LEASES l,
                         INTERNAL_REMARK r, INTERNAL_CAR_LEASE cl,
                         clm_lastsighting_view v1, clm_crossreference_view v2,
INTERNAL_CODES e, INTERNAL_CLM c
                        LEFT JOIN (INTERNAL_TRIPS t, INTERNAL_SPLC s)
                                 ON (c.trip_id = t.trip_id
                                 AND t.origin_splc_id = s.splc_id)
                        WHERE cu.id = ".$id."
                        AND cu.comp_id = m.comp_id
                        AND m.master_lease_id = l.master_lease_id
                        AND l.lease_id = cl.lease_id
                        AND cl.end_date IS NULL
                        AND cl.remark_id = r.remark_id
                        AND r.car_mark = c.car_mark
                        AND c.car_mark = v1.car_mark
                        AND v1.car_mark = v2.car_mark
                        AND r.car_number = c.car_number
                        AND c.car_number = v1.car_number
                        AND v1.car_number = v2.car_number
                        AND c.sighting_date = v1.sighting_date
                        AND c.sighting_code = v2.code
                        AND c.sighting_code = e.code
                        ORDER BY ".$order_by;
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
return $result;
}

function SELECT_sightings_leasecars($lease_id,$order_by){
$query = "SELECT c.l_e,
                                 c.car_mark, c.car_number,
                                 c.location_city, c.location_state,
                                 c.sighting_date,
                                 e.classification,
                                 c.railroad,
                                 s.city as origin_city,
                                 s.state as origin_state,
                                 c.destination_city, c.destination_state,
                                 t.eta
                        FROM INTERNAL_REMARK r, INTERNAL_CAR_LEASE cl,
clm_lastsighting_view v1,
                                 clm_crossreference_view v2, INTERNAL_CODES e, INTERNAL_CLM c
                        LEFT JOIN (INTERNAL_TRIPS t, INTERNAL_SPLC s)
                                 ON (c.trip_id = t.trip_id
                                 AND t.origin_splc_id = s.splc_id)
                        WHERE cl.lease_id = ".$lease_id."
                        AND cl.end_date IS NULL
                        AND cl.remark_id = r.remark_id
                        AND r.car_mark = c.car_mark
                        AND c.car_mark = v1.car_mark
                        AND v1.car_mark = v2.car_mark
                        AND r.car_number = c.car_number
                        AND c.car_number = v1.car_number
                        AND v1.car_number = v2.car_number
                        AND c.sighting_date = v1.sighting_date
                        AND c.sighting_code = v2.code
                        AND c.sighting_code = e.code
                        ORDER BY ".$order_by;
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
return $result;
}

?>

Posted by Paul Lautman on July 19, 2008, 3:41 am
Please log in for more thread options
JRough wrote:
>I have tried this 4 2 weeks and I need some help. There are 3 other
> pages referenced on this page but I'm going to start with this page
> in case I missed something. It is called current_sightings.php. All
> I want to do is redirect to Excel in the case of the External user.
> The first if statement creates a form. The elseif redirects the
> external user to only his own listings. I want the results for the
> Internal user query SELECT_sightings_leasecars.() to go to my
> current_sightingsXL.php page. Where/How would I put the redirect? I
> think it should be after the switch for external users. The
> getTableHeaders() function is the string that gets passed. All the
> pages work except I can't redirect the output to Excel.

What do you mean by "redirect the output to Excel"??? Excel isn't a
location, it's a spreadsheet program that some (but not all users) will have
on their machine.

BTW, Location: is supposed to take a fully qualified URL.



Posted by Jeff on July 19, 2008, 8:39 am
Please log in for more thread options
Paul Lautman wrote:
> JRough wrote:
>> I have tried this 4 2 weeks and I need some help. There are 3 other
>> pages referenced on this page but I'm going to start with this page
>> in case I missed something. It is called current_sightings.php. All
>> I want to do is redirect to Excel in the case of the External user.
>> The first if statement creates a form. The elseif redirects the
>> external user to only his own listings. I want the results for the
>> Internal user query SELECT_sightings_leasecars.() to go to my
>> current_sightingsXL.php page. Where/How would I put the redirect? I
>> think it should be after the switch for external users. The
>> getTableHeaders() function is the string that gets passed. All the
>> pages work except I can't redirect the output to Excel.
>
> What do you mean by "redirect the output to Excel"??? Excel isn't a
> location, it's a spreadsheet program that some (but not all users) will have
> on their machine.
>
> BTW, Location: is supposed to take a fully qualified URL.

What is a fully qualified URL? A Google search has left me more confused
than before.

Now, this is of course, fully qualified:

header("Location: http://www.example.com/");

and this presumably isn't:

header("Location: www.example.com/");

But what about this?:

header("Location: /new_page_in_html_root.html");

or:

header("Location: page_in_same_directory.html");

Now, as far as what the op wants, which isn't clear, you can use a
header statement (and have it work) as long as there the is no html
outputted (either echoed or embedded) before the header.


Jeff
>
>

Posted by Paul Lautman on July 19, 2008, 9:13 am
Please log in for more thread options
Jeff wrote:
> Paul Lautman wrote:
>> JRough wrote:
>>> I have tried this 4 2 weeks and I need some help. There are 3 other
>>> pages referenced on this page but I'm going to start with this page
>>> in case I missed something. It is called current_sightings.php. All I
>>> want to do is redirect to Excel in the case of the External
>>> user. The first if statement creates a form. The elseif
>>> redirects the external user to only his own listings. I want the
>>> results for the Internal user query SELECT_sightings_leasecars.()
>>> to go to my current_sightingsXL.php page. Where/How would I put
>>> the redirect? I think it should be after the switch for external
>>> users. The getTableHeaders() function is the string that gets
>>> passed. All the pages work except I can't redirect the output to
>>> Excel.
>>
>> What do you mean by "redirect the output to Excel"??? Excel isn't a
>> location, it's a spreadsheet program that some (but not all users)
>> will have on their machine.
>>
>> BTW, Location: is supposed to take a fully qualified URL.
>
> What is a fully qualified URL? A Google search has left me more
> confused than before.
>
> Now, this is of course, fully qualified:
>
> header("Location: http://www.example.com/");
>
> and this presumably isn't:
>
> header("Location: www.example.com/");
>
> But what about this?:
>
> header("Location: /new_page_in_html_root.html");
>
> or:
>
> header("Location: page_in_same_directory.html");
From the php manual:
HTTP/1.1 requires an absolute URI as argument to Location: including the
scheme, hostname and absolute path, but some clients accept relative URIs.
You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and
dirname() to make an absolute URI from a relative one yourself:
<?php
header("Location: http://" . $_SERVER['HTTP_HOST']
. rtrim(dirname($_SERVER['PHP_SELF']), '/\')
. "/" . $relative_url);
?>

> Now, as far as what the op wants, which isn't clear, you can use a
> header statement (and have it work) as long as there the is no html
> outputted (either echoed or embedded) before the header.
I have absolutely no idea what the OP wants since what he described doesn't
exist.



Posted by John Dunlop on July 19, 2008, 10:00 am
Please log in for more thread options
Jeff:

> What is a fully qualified URL?

One that is absolute, not relative, I would presume.

> A Google search has left me more confused than before.

Likely bitten by the terminology: "fully qualified" collocates with
domain names; "absolute" is a technical term to describe URLs.

> Now, this is of course, fully qualified:
>
> header("Location:http://www.example.com/");
>
> and this presumably isn't:
>
> header("Location:www.example.com/");

Indeed.

> But what about this?:
>
> header("Location: /new_page_in_html_root.html");

Termed an "absolute-path reference". Not an absolute URL, so violates
RFC 2616.

> or:
>
> header("Location: page_in_same_directory.html");

Termed a "relative-path reference". Again, not an absolute URL.

--
Jock

Similar ThreadsPosted
redirect / new website how to redirect old (google) links to new site ? November 7, 2006, 3:22 am
redirect to directory - php redirect or htaccess? June 25, 2006, 7:17 pm
PHP COM Excel Obj May 31, 2006, 7:06 pm
run excel October 30, 2006, 12:35 am
PHP with Excel January 16, 2007, 5:03 am
Excel PHP April 9, 2007, 10:55 am
Excel Help Please! August 10, 2007, 12:47 pm
PHP COM and Excel September 25, 2008, 11:38 am
excel and download July 19, 2004, 1:49 pm
Excel and PHP COM programming. November 7, 2004, 10:07 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap