Also, I would watch my headers very carefully, IE can be such a pain
in the bottom with the Expires: 0 .. because IE deletes the file
before your other app has a chance to open it. Basically, IE downloads
the file and deletes it immediately, stating that the file cannot be
found.
Way to go M$!
On May 8, 9:14 pm, "Christopher E. Franklin, Sr."
<[EMAIL PROTECTED]> wrote:
> Hello wonderful group!
>
> I have written some code that in essence, takes a date range and
> serves up two different formats depending what button you click.
>
> Firstly, is the "View" button. So, for example, I select a date range
> and click view, I get a table on the same page with the information I
> need. This works fine in IE7 and Firefox.
>
> Secondly, I have another button called "Export". Basically, it is the
> same form with the date ranges except, when I click the button, it
> calls a different function in my controller. The controller gets the
> data from the model and packages it via a component as comma separated
> values (CSV). It then just echos out the PHP headers and the CSV
> data.
>
> My problem is, it works fine in Firefox. When I click export, the
> date range is submitted, and I get a download window for the xls
> file. But, when I do the same thing in IE7 and IE6, I get an error
> stating that:
>
> "Internet Explorer cannot download renewals_certificate_export from
> subdomain.domain.com"
>
> "Internet Explorer was not able to open this Internet site. The
> requested site is either unavailable or cannot be found. Please try
> again later."
>
> So, while this error message is being displayed, I see the download
> box in the background, like it is ready to download. So, that tells
> me that the headers for php are correct but, I cannot figure out why
> IE7 has a problem downloading variable data on the fly.
>
> I have tried changing the headers to something else to no avail. I
> have tried making the URL different by including the full URL, with an
> ending slash (/) and also by including a file name on the end and
> accepting it in my controller function (/text.xls).
>
> I am at a loss here. So, I know it's a problem with IE7, not CakePHP
> or with the PHP headers. Just wondering if anyone has had a similar
> problem? If so, were you able to resolve the issue?
>
> Here is my code:
>
> Controller
> -------------
>
> function renewals_certificate_export($name = null) {
> Configure::write('debug', 0);
> if(!empty($this->data)) {
> $from = date('Y-m-d', strtotime($this->data['Report']
> ['from_month']."/".$this->data['Report']['from_day']."/".$this->data['Report']['from_year']))."
> 00:00:00";
>
> $to = date('Y-m-d',
> strtotime($this->data['Report']['to_month']."/".
> $this->data['Report']['to_day']."/".$this->data['Report']
> ['to_year']))." 23:59:59";
> $not = '';
> if($this->data['Report']['stager'] == 0) {
> $not .= "AND type != 'Stager' ";
> }
> if($this->data['Report']['master'] == 0) {
> $not .= "AND type != 'Master' ";
> }
> if($this->data['Report']['realtor'] == 0) {
> $not .= "AND type != 'Realtor' ";
> }
> if($this->data['Report']['iahsp'] == 0) {
> $not .= "AND type != 'Iahsp'";
> }
> $results = $this->Report->findAll("date >= '$from'
> AND date <=
> '$to' $not");
> foreach($results as $key => $value) {
> $user =
> $this->Asp->findByUid($value['Report']['uid']);
> $results[$key]['Report']['first_name'] =
> $user['Asp']['fname'];
> $results[$key]['Report']['last_name'] =
> $user['Asp']['lname'];
> $results[$key]['Report']['email'] =
> $user['Asp']['email'];
> $results[$key]['Report']['expiration_date'] =
> $user['Asp']
> ['anniversary'];
> }
> $this->Excel->addRow(array("ID", "First Name", "Last
> Name", "Type",
> "Email", "Expiration Date"));
> foreach($results as $key => $value) {
>
> $this->Excel->addRow(array($value['Report']['uid'],
> $value['Report']['first_name'], $value['Report']['last_name'],
> $value['Report']['type'], $value['Report']['email'], date('Y-m-d',
> strtotime($value['Report']['expiration_date']))));
> }
> $this->Excel->download(date('Y-m-d',
> strtotime($this->data['Report']
> ['from_month']."/".$this->data['Report']['from_day']."/".$this->data['Report']['from_year']))."_".date('Y-m-d',
> strtotime($this-
> >data['Report']['to_month']."/".$this->data['Report']['to_day']."/".
>
> $this->data['Report']['to_year'])).".xls");
> }
> }
>
> Excel Component
> --------------------------
>
> class ExcelComponent extends Object {
> var $lines;
>
> function addRow($data) {
> if(is_array($data)) {
> foreach($data as $key => $value) {
> $this->lines .= trim($value)."\t";
> }
> $this->lines = str_replace("\r","",$this->lines);
> $this->lines .= "\n";
> } else {
> trigger_error("Expecting an array to add for a row to
> the excel
> sheet");
> exit;
> }
> }
>
> function download($file_name = null) {
> if($file_name == null) {
> $file_name = "export.xls";
> }
> header("Content-type: application/vnd.ms-excel");
> header("Content-Disposition: attachment;
> filename=$file_name");
> header("Pragma: no-cache");
> header("Expires: 0");
> print $this->lines;
> exit;
> }
>
> }
>
> View for initial page (NOT THE VIEW FOR THE EXPORT FUNCTION)
> ----------------------------------------------------------------------------------------------------
>
> <style type="text/css">
> #calendarcontainer {padding:10px;}
> #calendarmenufrom, #calendarmenuto {position: absolute;}
> #calendarpickerfrom button, #calendarpickerto button {
> background: url(/js/yui/build/button/assets/skins/sam/
> calendar_icon.gif) center center no-repeat;
> text-align: left;
> text-indent: -10em;
> overflow: hidden;
> *margin-left: 10em; /* For IE */
> *padding: 0 3em; /* For IE */
> white-space: nowrap;}
>
> #ReportFromMonth, #ReportFromDay, #ReportToDay, #ReportToMonth {width:
> 2em;}
> #ReportFromYear, #ReportToYear {width: 3em;}
> #datefields {
> border: solid 1px #666;
> padding: .5em;}
>
> #calendarpickerfrom, #calendarpickerto {vertical-align: baseline;}
> </style>
> <h1 class="title">Renewal Certificate Report Generator</h1>
> <p>Select the date range which you wish to view.</p>
> <?php echo $form->create('Report', array('action' =>
> 'renewals_certificate')); ?>
> <fieldset>
> <legend>Search Criteria</legend>
> <p>
> <?php echo $form->checkbox('stager', array('checked' =>
> true)); ?>
> <?php echo $form->checkbox('master', array('checked' =>
> true)); ?>
> <?php echo $form->checkbox('realtor', array('checked' =>
> true)); ?>
> <?php echo $form->checkbox('iahsp', array('checked' =>
> true)); ?>
> </p>
> <script type="text/javascript">
> // Checkbox Buttons
> var oReportStager = new YAHOO.widget.Button("ReportStager",
> { label:"Stager" });
> var oReportMaster = new YAHOO.widget.Button("ReportMaster",
> { label:"Master" });
> var oReportRealtor = new YAHOO.widget.Button("ReportRealtor",
> { label:"Realtor" });
> var oReportIahsp = new YAHOO.widget.Button("ReportIahsp",
> { label:"Iahsp" });
>
> // Calendar Functions
> YAHOO.util.Event.onDOMReady(function () {
> function onCalendarFromButtonClick() {
> oCalendarFromMenu.setBody(" ");
> oCalendarFromMenu.body.id = "calendarcontainer";
> oCalendarFromMenu.render(this.get("container"));
> oCalendarFromMenu.align();
> var oCalendarFrom = new
> YAHOO.widget.Calendar("buttoncalendar", oCalendarFromMenu.body.id);
> oCalendarFrom.render();
>
> oCalendarFrom.changePageEvent.subscribe(function () {
> window.setTimeout(function () {
> oCalendarFromMenu.show();
> }, 0);
>
> });
>
> oCalendarFrom.selectEvent.subscribe(function (p_sType,
> p_aArgs) {
> var aDate;
> if (p_aArgs) {
> aDate = p_aArgs[0][0];
> YAHOO.util.Dom.get("ReportFromMonth").value =
> aDate[1];
> YAHOO.util.Dom.get("ReportFromDay").value =
> aDate[2];
> YAHOO.util.Dom.get("ReportFromYear").value =
> aDate[0];
> }
> oCalendarFromMenu.hide();
> });
> this.unsubscribe("click", onCalendarFromButtonClick);
> }
>
> function onCalendarToButtonClick() {
> oCalendarToMenu.setBody(" ");
> oCalendarToMenu.body.id = "calendarcontainer";
> oCalendarToMenu.render(this.get("container"));
> oCalendarToMenu.align();
> var oCalendarTo = new
> YAHOO.widget.Calendar("buttoncalendar", oCalendarToMenu.body.id);
> oCalendarTo.render();
>
> oCalendarTo.changePageEvent.subscribe(function () {
> window.setTimeout(function () {
> oCalendarToMenu.show();
> }, 0);
>
> });
>
> oCalendarTo.selectEvent.subscribe(function (p_sType,
> p_aArgs) {
> var aDate;
> if (p_aArgs) {
> aDate = p_aArgs[0][0];
> YAHOO.util.Dom.get("ReportToMonth").value =
> aDate[1];
> YAHOO.util.Dom.get("ReportToDay").value =
> aDate[2];
> YAHOO.util.Dom.get("ReportToYear").value =
> aDate[0];
> }
> oCalendarToMenu.hide();
> });
> this.unsubscribe("click", onCalendarToButtonClick);
> }
>
> var oCalendarFromMenu = new
> YAHOO.widget.Overlay("calendarmenufrom");
> var oCalendarToMenu = new
> YAHOO.widget.Overlay("calendarmenuto");
>
> var oCalendarFromButton = new YAHOO.widget.Button({
> type: "menu",
> id: "calendarpickerfrom",
> label: "From",
> menu: oCalendarFromMenu,
> container:
> "date_fields_from" });
> var oCalendarToButton = new YAHOO.widget.Button({
> type: "menu",
> id: "calendarpickerto",
> label: "To",
> menu: oCalendarToMenu,
> container:
> "date_fields_to" });...
>
> read more ยป
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---