if ($nav->action == "activ") { /* Get the exported data from the carry object */ $activ_data = $carry->retrieve("export", "activ_data") ; $nh_activ_data = $carry->retrieve("export", "nh_activ_data"); /* Get the filename from the carry object -- necessary so the timestamp matches */ $filename = $carry->retrieve("export", "filename"); /* Re-carry the data in case we have to reload */ $carry->store("export", "activ_data", $activ_data); $carry->store("export", "nh_activ_data", $nh_activ_data); $carry->store("export", "filename", $filename); /* Send the data to Smarty, switching templates in the process */ //$content_tpl = set_content_tpl($smarty, $nav->section, "export2-data"); $smarty->assign("activ_data", $activ_data); $smarty->assign("nh_activ_data", $nh_activ_data); /* Only do the export if there was actual data to export */ if (count($activ_data) == 0) { $feedback->conf("There were no records to export."); $content_tpl = set_content_tpl($smarty, "blank", "index"); } else { $buffer = ""; foreach ($activ_data as $export) { $line = ""; $line .= $export["last"] . "\t"; $line .= $export["first"] . "\t"; $line .= "AS" . $export["activslip"] . "\t"; $line .= date("m/d/Y", strtotime($export["date"])) . "\t"; $line .= $export["wc_code"] . " " . $export["wc_description"] . "\t"; $line .= $export["client_code"] . " " . $export["company_name"] . " (" . $export["contact"] . ")" . "\t"; $line .= " " . "\t"; $line .= $export["duration"] . "\t"; $line .= $export["rate"] . "\t"; $line .= $export["job_code"] . "\t"; $line .= $export["description"] ; $line = strip_line_breaks($line); $line .= "\r"; $buffer .= $line; } foreach ($nh_activ_data as $export) { $line = ""; $line .= $export["last"] . "\t"; $line .= $export["first"] . "\t"; $line .= "AS" . $export["activslip"] . "\t"; $line .= date("m/d/Y", strtotime($export["date"])) . "\t"; $line .= $export["wc_code"] . " " . $export["wc_description"] . "\t"; $line .= $export["client_code"] . " " . $export["company_name"] . " (" . $export["contact"] . ")" . "\t"; $line .= " " . "\t"; $line .= $export["quantity"] . "\t"; $line .= $export["rate"] . "\t"; $line .= $export["job_code"] . "\t"; $line .= $export["description"] ; $line = strip_line_breaks($line); $line .= "\r"; $buffer .= $line; } /* Write to disk */ $handle = fopen("data/export/activ/$filename.txt", "w"); //if (fwrite($handle, $smarty->fetch("$content_tpl")) == false) { // echo("Could not write to file $filename.txt"); //} if (fwrite($handle, $buffer) == false) { echo("Could not write to file $filename.txt"); } fclose($handle); unset($buffer); /* Create the export record in the database */ $sql = "INSERT INTO export_activ SET date='$filename'"; if (! $database->insert($sql) ) { echo("Could not create activity export record."); } else { $carry->store("export", "export_id", $database->insert_id()); } $smarty->assign("file_data", file_date_info($filename)); /* the URL parameters should result in the template output being downloaded as a text/plain attachment. Now, we reset the value of $content_tpl so that we actually see a different page. */ set_content_tpl($smarty, $nav->section, "export2-conf"); } }